Altera Interview Question: Reverse the linked list.... | Glassdoor

Interview Question

Software Engineer Interview San Jose, CA

Reverse the linked list.

Answer

Interview Answer

1 Answer

0

Example:
1->2->3->4->5->6
All you need to do is let 1 point to null (Last node of linked list) and then reverse link between (1,2), (2,3) and so on.

Use 3 node variables to represent a 'size 3 moving window'
Node current;
Node next;
Node temp;

current = head;
next = head.next;
head.next = null;

while (next != null){
temp = next.next;
next.next = current;
current = next;
next = temp.next;
}

Akash on Apr 25, 2015

Add Answers or Comments

To comment on this, Sign In or Sign Up.