How would you reverse a doubly-linked list?
Submitted by: AdministratorThis 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
Read Online Microsoft Job Interview Questions And Answers
Top Microsoft Questions
☺ | Microsoft Interview Questions List |
☺ | How many gas stations are there in US? |
☺ | write a function that will take a sorted array, possibly with duplicates, and compact the array, returning the new length of the array? |
☺ | You are given a scale which you are to use to measure eight balls? |
☺ | How would you move Mt. Everest? |
Top Companies Job Categories
☺ | TCS Interview Questions. |
☺ | Infosys Interview Questions. |
☺ | IBM Interview Questions. |
☺ | Wipro Interview Questions. |
☺ | Google Interview Questions. |