CS115 Exercise: C++ Simple Linked Lists
Get Code For the Online Lab
The starting code is available on Replit:
- Sample code shown in the videos (main.cpp)
- Linked list exercise using "NULL"
- Linked list exercise using "nullptr"
To compile the linked list code, type
make
The purpose of the program is to
demonstrate operations on a simple singly linked list.
Exercise
Now you should be ready to start adding code to that program.
- First, in LinkedList.cpp, add the code to print out the
linked list.
The function called LinkedList::printList() is provided
in the code; you need to add the implementation.
Compile and run this C++ program.
- Now, add the code to add a single node element to the end of the list.
The function called LinkedList::appendItem() is provided
in the code; you need to add the implementation.
Compile and run this C++ program.
- Add the code to delete a node from the list.
The function called LinkedList::deleteItem() is provided
in the code; you need to add the implementation.
Compile and run this C++ program.
Try deleting the first, last and middle node. Also try to remove
something that is not in the list (an appropriate message should be
printed).
Test Run
Notice that you code should work when you are trying to delete and item at the beginning,
at the end, and in the middle.
It should also still work and provide a message if an item does not exist. Please try
the steps below to ensure that your code is working as expected before submitting.
- Make the list: 4 12 16 999
- Print
- Insert an 8
- Print
- Append a 30
- Print
- Delete the 4
- Print
- Delete the 30
- Print
- Delete the 12
- Print
- Try to delete a 2
- Print
[an error occurred while processing this directive]