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 *a
represent same thing? - in first code when declared:
queue < nodeptr >q
worked in second code when declaredqueue < node >q
didn't work. why?
are both codes represents same thing ?
they represent same thing, except first 1 defines nodeptr
typedef
ed name.
is int* , int *a represents same thing?
yes.
for first code when declared:
queue < nodeptr >q
worked second code when declared in code:queue < node >q
did 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