#include <iostream>
using namespace std;
struct Node
{
int nData;
Node * pNext;
};
Node *CreateList(Node* pHead)
{
Node * pTemp;
for(int i = 1;i<10;i++)
{
pTemp = new Node();
pTemp->nData = i;
pTemp->pNext = pHead;
pHead = pTemp;
}
return pHead;
}
Node *ReverseList(Node* pHead)
{
Node* p1 = pHead;
Node* p2 = NULL;
while(p1)
{
Node * pTemp = p1->pNext;
p1->pNext = p2;
p2 = p1;
p1 = pTemp;
}
return p2;
}
void ReverseList(Node** pHead)
{
Node* p1 = *pHead;
Node* p2 = NULL;
while(p1)
{
Node * pTemp = p1->pNext;
p1->pNext = p2;
p2 = p1;
p1 = pTemp;
}
*pHead = p2;
}
Node * ReverseList_Digui(Node* pHead,Node* pHead2 = NULL)
{
if(pHead == NULL)
return pHead2;
Node * pTemp = pHead->pNext;
pHead->pNext = pHead2;
return ReverseList_Digui(pTemp,pHead);
}
void Printf(Node* pHead)
{
Node * pTemp = pHead;
while(pTemp)
{
cout<<pTemp->nData<<",";
pTemp = pTemp->pNext;
}
cout<<endl;
}
int main()
{
Node * pHead;
pHead = new Node();
pHead->nData = 0;
pHead->pNext=NULL;
pHead = CreateList(pHead);
Printf(pHead);
pHead = ReverseList(pHead);
Printf(pHead);
ReverseList(&pHead);
Printf(pHead);
pHead = ReverseList_Digui(pHead);
Printf(pHead);
getchar();
}