** This bonus assignment can give you a max of 60 points, which is equal to one whole module worth 😉
Write a void function that takes a linked list of integers and reverses the order of its nodes. The function will have one call-by-reference parameter that is a pointer to the head of the list. After the function is called, this pointer will point to the head of a linked list that has the same nodes as the original list, but in the reverse of the order they had in the original list.
Note that your function will neither create nor destroy any nodes. It will simply rearrange nodes. Place your function in a suitable test program.
You are given the following five files:
What to Submit
Submit two files for this lab:
- Implement the reverse function in linkedlist.cpp
- You may add more functions that are needed to implement the above
- Your code will not cause any runtime errors such as segmentation faults
- Use visual aids to help you understand your plan for the function
- Consider boundary cases
- You might want to “rewrite” or “copy/type out” other functions that are already implemented to solidify your understanding with linked list first
- I had to use three pointers to accomplish this. Maybe you will beat me 😉
Suggestion: Change main.cpp to add more ways to test your reverse function implementation.
Just finished adding nodes
Current linked list: 4 3 2 1 0
Just finished reversing the linked list
Current linked list: 0 1 2 3 4