NVIDIA Interview Question

Q: Print a LL in reversed order. 1) recursive 2) non recursive

Interview Answer

Anonymous

Aug 12, 2015

void ReverseListRecursive(Node *head) { if(head != NULL) { ReverseList(head->next); printf(" %d \n", head->data); } return; } void reverse_non_recursive(Node **head){ if (!head) return; Node *prev=NULL; Node *cur = head; while(cur) { Node *next = cur->next; cur->bext= prev; prev=cur; cur=next; } head=prev; }