Lab 14A: Linked Lists

  < Previous  Next >

Objectives:

In this lab, we will practice linked list operations.

Assignment:

Complete the following tasks on a piece of paper and turn them into the Divya.
    1. Given the following struct definition of a linked list node:
      struct Node{
        int data;
        Node* next;
      };
      instantiations can be represented graphically with:
    2. After inserting 5 into the list, this could be represented with the following:

      Draw the resulting (traditional) linked list after each of the following instructions:
      1. Insert 5 (already done)
      2. Insert 9
      3. Insert 7
      4. Remove 9
      5. Remove 5
      6. Remove 7
      7. Remove 5
      For insertions, insert at the beginning of the list.
  1. What are the "special cases" or scenarios to test for for each operation (for adding, retrieving or removing an item)?
    1. ________________________________
    2. ________________________________
    3. ________________________________
    4. ________________________________ (general case)
    5. ________________________________
  2. Write C++ code for the following operations: (make sure that you address each scenario above)
    1. Inserting a node into a linked list
    2. Printing out the contents of every item in a linked list
    3. Removing an item from a linked list