If we illustrate a LinkedList this way:
Then after reversing the LinkedList should look like:
Let's forget a linked list and think about reversing an array [10, 20, 30, 40, 50]. How do we do that? We can simply swap the first and the last values, then swap the second and the second last value, and so on.
Works also for an even number of elements. Like here:
In the array, we can easily get the value at the i-th position, but in the Linked List we have to write a function that will do that. Since this is just going to be used inside a class method, we will make it a private function. So what it will do is get the node at the i-th index. Then we will swap the data. So the pseudo-code for the reverse will be :
And what about the getNodeAt(idx) function. We can simply run a loop till idx and keep moving a dummy pointer to its next node. The dummy pointer will be initialized with the head. And after the loop is over we will return it. This function is going to be very similar to that of getAt() but there we were returning the data here we would need the node itself.
Try to code this yourself.