Linked Lists Exercises

  < Previous  Next >
    1. Make a (traditional) linked list with the following instructions:
      1. Insert 5
      2. Insert 3
      3. Insert 9
      4. Insert 7
      5. Remove 5
      6. Remove 9
      7. Remove 3
      8. Remove 7
      9. Remove 5
    2. Draw the resulting linked list with nodes like:
    3. Enumerate the steps taken to build the linked list by labeling each of the actions with a consecrative number
  1. What are the "special cases" or scenarios to test for for each operation (for adding, retrieving or deleting an item)?
    1. ________________________________
    2. ________________________________
    3. ________________________________
    4. ________________________________ (general case)
    5. ________________________________
  2. Given:
    struct Node{
      int item;
      Node* next;
    };
    
    Node* head;
    Working in groups of 2-3 people, draw an example for your operation (see below). Next, write code for your operation. Make sure that you address each scenario above.
    if( MNumber % 10 <= 3 ){
      Insert a number into the linked list
    }else if( MNumber % 10 <= 6 ){
      Print out the contents of every item in a linked list
    }else{
      Look for 7 in the list and delete, if present
    }

Last Modified: