The purpose of this quiz is to give you a chance to focus your knowledge of simple linked lists in C++.
A linked list tries to improve on arrays (be they static or dynamic) by ____.
A node in a linked list consists of a data member and a pointer to the next node in the list at the very least.
Linked lists can come in various flavors. These include:
A node in a doubly-linked list adds a pointer to the previous node in the list to the basic design.
Write a [NONrecursive] function to print all elements of a singly-linked list given the list's head as your single argument.
void print_list(const Node * head) { const Node * walker = head; while (walker != nullptr) { print_data(walker->Data()); walker = walker->Next(); } return; }
Write a recursive function to print all elements of a singly-linked list given the list's head as your single argument.
void print_list(const Node * head) { if (head != nullptr) { print_data(head->Data()); print_list(head->Next()); } return; }
What would need to change in your function to have it print the elements of the list backwards?
Just reverse the calls to the function and the data printer like so: void print_list(const Node * head) { if (head != nullptr) { print_list(head->Next()); print_data(head->Data()); } return; }