Reverse A Linked List HackerRank
public static SinglyLinkedListNode reverse(SinglyLinkedListNode llist) {
SinglyLinkedListNode temp=llist;
Stack<Integer> stack=new Stack<Integer>();
while(temp!=null){
stack.push(temp.data);
temp=temp.next;
}
temp=llist;
while(!stack.isEmpty()){
temp.data=stack.pop();
temp=temp.next;
}
return llist;
// Write your code here
}
Comments
Post a Comment