Frage im Vorstellungsgespräch bei Cisco

Whiteboard coding: Reverse a linked list.

Antworten zu Vorstellungsgespräch

Anonym

16. Jan. 2015

Read it from start to end, build it from end to start.

Anonym

23. Jan. 2015

Read it from start to end, use temp variables to swap direction of pointers. For a linked list of integers that takes in a head pointer and returns a pointer to the head of the reversed list: int* reverseLL(int * head){ if(!head || !head->next) return head; int *prev = NULL; int *next = head; while(next){ head = next; next = next->next; head->next = prev; prev = head; } return head; }