#include <iostream>
using namespace std;
struct Node{
int data;
Node* next;
};
//Return pHead
Node* MakeUpList(int* nArray, int nLengthOfArray)
{
if (nLengthOfArray < 1) return NULL;
Node* pHead;
Node* nodeTemp = new Node;
nodeTemp->data = nArray[0];
for(int i = 1; i < nLengthOfArray; i++)
{
Node* nodeCurrent = new Node;
nodeCurrent->data = nArray[i];
if (i == nLengthOfArray - 1) nodeCurrent->next = NULL;
nodeTemp->next = nodeCurrent;
if (i == 1)
pHead = nodeTemp;
nodeTemp = nodeCurrent;
}
return pHead;
}
Node* ReverseList(Node* pHead)
{
if(pHead->next == NULL)
{
return pHead;
}
Node* Next = NULL;
Node* Prev = NULL;
while(pHead != NULL)
{
Next = pHead->next;
pHead->next = Prev;
Prev = pHead;
pHead = Next;
}
return Prev;
}
int main()
{
int nLength = 10;
int* nArray = new int[nLength];
for (int i = 0; i < nLength; i++)
{
nArray[i] = i + 1;
}
Node* pHead = MakeUpList(nArray, 10);
PrintList(pHead);
InsertList(&pHead, 100);
pHead = ReverseList(pHead);
PrintList(pHead);
system("pause");
return 0;
}