Topical Information

The purpose of this quiz is to give you a chance to focus your knowledge of simple linked lists in C++.

Quiz Information

Questions

  1. A linked list tries to improve on arrays (be they static or dynamic) by ____.

    1. adding a[t least one] pointer to each piece of data NO
    2. helping the OS manage memory better for [re]allocation YES
    3. speeding up insertion of data YES
    4. speeding up deletion of data YES
    5. speeding up access to data NO
  2. 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.

  3. Linked lists can come in various flavors. These include:

    1. singly-linked linear lists YES
    2. doubly-linked linear lists YES
    3. singly-linked circular lists YES
    4. doubly-linked circular lists YES
    5. toaster ovens NO
  4. A node in a doubly-linked list adds a pointer to the previous node in the list to the basic design.

  5. 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;
        }
    
    
  6. 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;
        }