2013-02-19 41 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()将它从堆栈中移除。