Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > Re: std::stack ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 45759 of 47006
Post > Topic >>

Re: std::stack compilation error

by Christian Hackl <hacki@[EMAIL PROTECTED] > May 5, 2008 at 05:32 PM

Rahul wrote:

> void dfs(struct node * root)
> {
>  if(root == NULL) return;
>  std::stack <struct node *> s;

You don't need the struct keyword here.

>  s.push(root);
> 
>  while(!s.empty())
>  {
>   struct node * temp = s.pop();

That's not how std::stack works. top() and pop() are separate functions:
http://www.cppreference.com/cppstack/index.html

>   printf("%d ",temp->data);
>   s.push(temp->rptr);
>   s.push(temp->lptr);
>  }
> }
> 
> and i get a error saying,
> 
>  ro.c: In function `void dfs(node*)':
> ro.c:419: `stack' undeclared in namespace `std'
> 
> Am i missing something?

#include <stack> ?


-- 
Christian Hackl
 




 3 Posts in Topic:
std::stack compilation error
Rahul <sam_cit@[EMAIL   2008-05-05 08:19:16 
Re: std::stack compilation error
Christian Hackl <hacki  2008-05-05 17:32:14 
Re: std::stack compilation error
Rahul <sam_cit@[EMAIL   2008-05-05 08:48:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Jul 24 1:59:21 CDT 2008.