Interview Questions Answers.ORG
Interviewer And Interviewee Guide
Interviews
Quizzes
Home
Quizzes
Interviews Companies Job Interviews:AppleCompany KnowledgeFedExGoogleIBMInfosysMicrosoftTCSWipro
Copyright © 2018. All Rights Reserved
Microsoft Interview Question:
How would you reverse a doubly-linked list?
Submitted by: AdministratorAd
This problem isn't too hard. You just need to start at the head of the list, and iterate to the end. At each node, swap the values of pNext and pPrev. Finally, set pHead to the last node in the list.
Node * pCurrent = pHead, *pTemp;
while (pCurrent)
{ pTemp = pCurrent-gt;pNext;
pCurrent-gt;pNext = pCurrent->pPrev;
pCurrent-gt;pPrev = temp;
pHead = pCurrent;
pCurrent = temp;
}
Submitted by: Administrator
Node * pCurrent = pHead, *pTemp;
while (pCurrent)
{ pTemp = pCurrent-gt;pNext;
pCurrent-gt;pNext = pCurrent->pPrev;
pCurrent-gt;pPrev = temp;
pHead = pCurrent;
pCurrent = temp;
}
Submitted by: Administrator
Copyright 2007-2025 by Interview Questions Answers .ORG All Rights Reserved.
https://InterviewQuestionsAnswers.ORG.

https://InterviewQuestionsAnswers.ORG.
