Interviewer And Interviewee Guide

Data Structure Linked list Interview Question:

Explain the most efficient method to reverse a linked list?

Submitted by: Muhammad
To call the function:
newHead = reverse(head);

struct Node *reverse(Node *curp)
{
static struct Node *head = curp;
static struct Node *revHead = NULL;
if (curp == NULL)
return NULL;
if (curp->next == NULL)
revHead = curp;
else
reverse(curp->next)->next = curp;
if (curp == head) {
curp->next = NULL;
return revHead;
}
else
return curp;
}
Submitted by: Muhammad

Read Online Data Structure Linked list Job Interview Questions And Answers
Copyright 2007-2024 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.