public void swapFirstLast(){
Node current = head;
Node previous = null;
while(current.next != null){
previous = current;
current = current.next;
}
Node temp = head;
current.next = temp.next;
previous.next = temp;
temp.next = null;
head = current;
}
No comments:
Post a Comment