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:

  1. do both codes represent same thing?
  2. does int* a , int *a represent same thing?
  3. in first code when declared: queue < nodeptr >q worked in second code when declared queue < node >q didn'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 >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

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -