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

Use C++ programming please 5. (Weight: 2596) PROGRAMMING-Using the single-linked

ID: 3748515 • Letter: U

Question

Use C++ programming please

5. (Weight: 2596) PROGRAMMING-Using the single-linked list shown in the figure below, d assuming that head references the first Node and tail references the last Node, write statements to do each of the following. a. Insert "Bill" before "Tom" (You have a reference to the head (Tom)). b Insert "Sue" before "Sam" (You only have a reference to Sam and the head). c. Remove "Bill" d. Remove "Sam" (You only have a reference to the head and Sam). Node Node Node Node next data="Tom" next = data="John next = next = data- "Sam" data "Harry"

Explanation / Answer

Inserting Bill Before Tom

Node *newNode;
newNode = new Node;
newNode ->link =NULL;
newNode ->data = "Bill";
newNode ->link=head;
head = newNode;

Ans2.

Node *newNode;
newNode = new Node;
newNode ->link =tail->link;
newNode ->data = "Sue";
tail->link=newNode;

Ans3.

Node *tmp = head->link;
delete head;
head = tmp;

Ans4.

Node *tmp=tail->link;
delete tmp;
tail->link=NULL;

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