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

C++ Design a struct for a doubly-linked list as follows: Taie teed prev pies Nex

ID: 3740021 • Letter: C

Question

C++




Design a struct for a doubly-linked list as follows: Taie teed prev pies Next Next NUL Create a linked list as indicated above. Write a function called dowmvardSearch(listrec? head) that utilizes the next pointer to traverse from the start of a linked list to the end of the linked list and print out the value of each node along the way. Develop another function called upwardSearchlistrec2 tail) that utilizes the prey pointer to traverse from the end of a linked list to the start of the linked list and print out the value of each node along the way. In your main routine, you need to create two pointer variables:h ail, which points to the beginning and end of the linked list. Then, you feed these two variables to the functions downwardSearch) and upwardSearch( ), respectively

Explanation / Answer

void downwardSearch(listrec2 *head)

{

listrec2 *temp = head;

while (temp != NULL)

{

printf("%d ", temp->data);

temp = temp->next;

}

}

void upwardSearch(listrec2 *tail)

{

listrec2 *temp = tail;

while (temp != NULL)

{

printf("%d ", last->data);

temp = temp->prev;

}

}

//For finding tail we can use this:

listrec2* findTail(listrec2 *head)

{

listrec2 *temp = head;

while (temp->next != NULL)

{

tail = temp;

temp = temp->next;

}

return tail;

}

listrec2 *tail = findTail(head);

  

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