c++ - What are the differences between the following codes -
given code:
#include <iostream> using namespace std; int main() { typedef struct node { int data; node* left; node* right; } *nodeptr; nodeptr root, curr, temp; } and second code:
#include <iostream> using namespace std; int main() { struct node { int data; node *left; node *right; } node *root, *curr, *temp; } i have few questions:
- do both codes represent same thing?
- does
int* a,int *arepresent same thing? - in first code when declared:
queue < nodeptr >qworked in second code when declaredqueue < node >qdidn't work. why?
are both codes represents same thing ?
they represent same thing, except first 1 defines nodeptr typedefed name.
is int* , int *a represents same thing?
yes.
for first code when declared:
queue < nodeptr >qworked second code when declared in code:queue < node >qdid not worked. why?
queue<nodeptr> q same queue<node*> q. hence comparison not appropriate.
you should able use queue<node> if use c++11. see working @ http://ideone.com/tkij08.
Comments
Post a Comment