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.
-
- Given the following struct definition of a linked list node:
struct Node{
int data;
Node* next;
};
instantiations can be represented graphically with:
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:
- Insert 5 (already done)
- Insert 9
- Insert 7
- Remove 9
- Remove 5
- Remove 7
- Remove 5
For insertions, insert at the beginning of the list.
What are the "special cases" or scenarios to test for for each operation (for adding, retrieving or removing an item)?
- ________________________________
- ________________________________
- ________________________________
- ________________________________ (general case)
- ________________________________
Write C++ code for the following operations: (make sure that you address each scenario above)
- Inserting a node into a linked list
- Printing out the contents of every item in a linked list
- Removing an item from a linked list