How do I refer to the tail variable inside the take_input() function so that it reflects in the main ?
Below are the main() and take_input() functions
Here I've tried to pass by reference [ **tail ]
How do I refer to this inside the take_input() function for the linked list { *tail is causing an error }
Any help would be highly appreciated !!!!
node* take_input(node **tail)
{
node* head = NULL;
int count = 0;
string name;
cout << "Enter the name of the president";
cin >> name;
while(!name.empty())
{
count++ ;
node *new_node = new node(name);
if(head == NULL)
{
head = new_node;
*tail = new_node;
}
else
{
*tail->next = new_node ;
*tail= *tail->next;
}
cout << "Enter the name of a member , the secretary or NULL to exit";
cin >> name ;
}
return head;
}
int main()
{
int n ;
string name;
node *tail = NULL;
node *head = take_input(&tail);
cin >> n;
cin >> name;
node *headfinal = insert_node(head, n ,name);
cout<< "\n Enter the member's name which needs to be deleted\n";
string del;
cin >> del;
node *head_final2 = delete_node(headfinal,del, &tail);
node *temp2 = head_final2 ;
while(temp2 != NULL)
{
cout << temp2->name;
temp2 = temp2->next;
}
This is the error I am currently facing:
expression must have a pointer to class type (c/c++) (131,5)
**has meaning in C++ that isn't "bold". If you need to, add comments with//or/* ... */.node * take_input (node * & tail). Then in main, you can simply callnode * head = take_input(tail);.nullptrin preference to C'sNULL. Also there's a strong convention to not have any space around->, so usex->yto make it clear what's going on there.