reverse function 3


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


You are given the following five files:






What to Submit

Submit two files for this lab:

  1. linkedlist.h
  2. linkedlist.cpp


  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


  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


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