2013-02-19 79 views
-4

我試圖用C++編譯這個函數沒有成功。java stack - pop

這是一個java代碼。主要是打電話給'測試'。我只是想知道,如果S堆發送的所有或S是部分發送(不含7),因爲s.pop()

bool test(stack<int> s, int x) { 
    int y; 
    if (!s.empty()) { 
     y = s.pop(); 
     return x==y || test(s,y); 
    } 
    else return false; 
} 

int main() 
{ 
    stack<int> s; 
    s.push(2); 
    s.push(5); 
    s.push(1); 
    s.push(2); 
    s.push(7); 
    int x = 4; 
    test(s, s.pop()); 
return (0); 
} 
+8

Java在這整個事情在哪裏? – amphibient 2013-02-19 22:12:26

+4

當然,如果你回頭看這個問題,你會意識到這是不可能理解的。 – 2013-02-19 22:12:27

+0

顯示彙編錯誤 – noMAD 2013-02-19 22:13:17

回答

1

如果您使用的是的std ::棧,流行的()不會返回值。您必須使用top()來訪問頂層元素。然後你可以使用pop()將它從堆棧中移除。