reverse function 3

Description

** 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.

Watchvideo 13-7 (Links to an external site.)for a run through of the lab. https://www.youtube.com/watch?v=wDOZ1GXepmw

Given

You are given the following five files:

main.cpp

node.h

node.cpp

linkedlist.h

linkedlist.cpp

What to Submit

Submit two files for this lab:

  1. linkedlist.h
  2. linkedlist.cpp

Requirements

  1. Implement the reverse function in linkedlist.cpp
  2. You may add more functions that are needed to implement the above
  3. Your code will not cause any runtime errors such as segmentation faults

Tips

  1. Use visual aids to help you understand your plan for the function
  2. Consider boundary cases
  3. You might want to “rewrite” or “copy/type out” other functions that are already implemented to solidify your understanding with linked list first
  4. I had to use three pointers to accomplish this. Maybe you will beat me 😉

Test Cases

main.cpp

Suggestion: Change main.cpp to add more ways to test your reverse function implementation.

Demo

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