Reverse a Linked List


public Node reverseList(Node head){
		Node temp=head;
		Node nextNode=null,prevNode=null;
		while(temp!=null){
			nextNode=temp.getNext();
			temp.setNext(prevNode);
			prevNode=temp;
			head=temp;
			temp=nextNode;
		}
		return head;
	}


Leave a Reply

Your email address will not be published. Required fields are marked *