Get Started
637

Q: How would you reverse a doubly-linked list?

  • उत्तर देखें
  • Workspace

Answer :
Explanation :

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->pNext;   pCurrent->pNext = pCurrent->pPrev;   pCurrent->pPrev = temp;     pHead = pCurrent;   pCurrent = temp; }

सबसे विस्तृत एग्जाम तैयारी प्लेटफार्म

Examsbook Prep ऐप आज ही प्राप्त करें