Made a function to reverse a linked list