int insert(node* head) {
if (head == NULL) {
node* temp = new node;
if (head == NULL) {
cout << "Error";
return 0;
}
temp->data = 20;
temp->next = NULL;
} else {
temp->next = insert(temp->next);
}
return (temp);
}
I am trying to add node recursively but I got the error temp was not declared. I do not understand why I am getting this error. When I always define temp like this node* temp = new node; but now I got an error.
insertto return something. Besides, your return type isintbut you're returning anode*inreturn temp. Just make the return typevoid.std::list'sinsertreturns an iterator to the inserted element.