- Joined
- Jun 7, 2023
- Messages
- 1
- Reaction score
- 0
please find what I'am doing wrong in this code.
3 5 7 9 null is my Linked List
output using this code 3 null
public Node reverseNode(Node head){
Node prevNode = null ;
Node currNode = head ;
Node tempNode = currNode ;
while (currNode != null) {
currNode.next = prevNode ;
prevNode = currNode ;
currNode = tempNode.next ;
tempNode = currNode ;
}
head = prevNode;
return head ;
}
3 5 7 9 null is my Linked List
output using this code 3 null
public Node reverseNode(Node head){
Node prevNode = null ;
Node currNode = head ;
Node tempNode = currNode ;
while (currNode != null) {
currNode.next = prevNode ;
prevNode = currNode ;
currNode = tempNode.next ;
tempNode = currNode ;
}
head = prevNode;
return head ;
}