Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function InsertCustomer that inserts a node at the end of the linked lis

ID: 3779570 • Letter: W

Question

Write a function InsertCustomer that inserts a node at the end of the linked list. Assume that the function receives a pointer (Head) which points to the first node of the linked list as an argument. Within the InsertCustomer function, the user enters the information about the customer node to be inserted into the linked list. Write a function PrintCustomerList the prints the values of all the nodes of the linked list on the screen starting from the last to the first using recursion. The function receives a pointer (Head) which points to the first node of the linked list as an argument.

Explanation / Answer

Here goes the solution for Question 3.

Code:

struct node{
int data;
Struct node *next;
}
void InsertCustomer(node *head) {
   //create a link
   struct node *link = (struct node*) malloc(sizeof(struct node));
   cout<<"Enter data";
   int data=0;
   cin>>data;  
   //give the data to the link      
   link->data = data;

//traverse to the end of the list  
while(head->next!= NULL){
   head=head->next;
}

assign the link to the next of the last node in the list
head->next=link;

link->next=NULL;
}

Explanation:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote