// LinkList.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct _node
{
int val;
struct _node* next;
}Node;
Node* ReverseList(Node* head)
{
if(!head||head->next==NULL)
return NULL;
Node* cur=head->next;
Node* pre=head;
pre->next=NULL;
Node* nex;
while(cur)
{
nex=cur->next;
cur->next=pre;
pre=cur;
cur=nex;
}
return pre;
}
int _tmain(int argc, _TCHAR* argv[])
{
int m=4;
Node* head=(Node*)malloc(sizeof(Node));
head->val=0;
head->next=NULL;
for(int i=1;i<=4;i++)
{
Node* n=(Node*)malloc(sizeof(Node));
n->val=i;
n->next=head;
head=n;
}
Node *tmp=ReverseList(head);
while(tmp)
{
cout<<tmp->val;
tmp=tmp->next;
}
cin.get();
return 0;
}