//Reverse linked list
NODE* ReverseLinkedList(NODE *pHead)
{
if (NULL == pHead)
return NULL;
NODE *pCurrent = pHead;
NODE *pCurrent1 = pHead->pNext;
//Make original head node as the last node of new list
pHead->pNext = NULL;
while(pCurrent1)
{
NODE *pTemp = pCurrent1->pNext;
pCurrent1->pNext = pCurrent;
pCurrent = pCurrent1;
pCurrent1 = pTemp;
}
return pCurrent; //the new head node
}
Monday, July 21, 2008
Subscribe to:
Post Comments (Atom)

0 comments:
Post a Comment