c++ - An error: expected constructor, destructor, or type conversion before '(' token -
i getting error in *insert_nodes function:
error: expected constructor, destructor, or type conversion before '(' token
i have problem in same function, sais have redeclare 'int nodes' parameter in function. think it's not necessary write this:
*insert_nodes(start, int nodes)
instead of being this:
*insert_nodes(start,nodes)
another error in getch(). while compiling in netbeans, shows error on place doesn't mention type of error.
struct tree_traversal { int data; tree_traversal *left; //left subtree tree_traversal *right; //right subtree }; tree_traversal *insert_nodes(tree_traversal *start, int nodes); void preordertraversal(tree_traversal *start); void postordertraversal(tree_traversal *start); void inordertraversal(tree_traversal *start); int counter = 1; int main(int argc, char **argv) { int choice, nodes; { switch(choice) { case 1: cout<<"\n\t\a\a enter values:\a\a"; cin>>nodes; start=insert_nodes(start,nodes); break; case 2: cout<<"\n\t\a\a values in-order tree traversal is: \a\a"<<endl; preordertraversal(start); break; case 3: cout<<"\n\t\a\a values in-order tree traversal is: a\a"<<endl; postordertraversal(start); break; case 4: cout<<"\n\t\a\a values in-order tree traversal is: \a\a"<<endl; inordertraversal(start); break; case 5: exit(0); } } while(choice != 5); return 0; } tree_traversal *insert_nodes(tree_traversal *start, int nodes) { if(start == null) { start = new tree_traversal; start ->left = start ->right = null; start ->data = nodes; counter++; } else if(counter%2 == 0) start ->left = insert_nodes(start ->left,nodes); else start ->right = insert_nodes(start ->right,nodes); return(start); } void preordertraversal(tree_traversal *start) { if(start != null) { cout<<start ->data; preordertraversal(start->left); preordertraversal(start->right); getch(); } } void postordertraversal(tree_traversal *start) { if(start != null) { postordertraversal(start->left); postordertraversal(start->right); cout<<start ->data; getch(); } } void inordertraversal(tree_traversal *start) { if(start != null) { inordertraversal(start->left); cout<<start ->data; inordertraversal(start->right); getch(); } }
*insert_nodes(start, int nodes)
should be
tree_traversal *insert_nodes(tree_traversal *start, int nodes) ^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^
you forgot mention data type return type & function argument in function definition.
yes, need specify data types of function arguments in function definition.
Comments
Post a Comment