#include
#include
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
typedef struct LNode{
int node;
struct LNode *next;
} LNode,*LinkList;
LinkList Head_Node()
{
LinkList head;
head=(LinkList)malloc(sizeof(LNode));
if(head==NULL)
{
printf("空间分配失败\n");
return head;
}
head->next=NULL;
return head;
}
int CreateList(LinkList head)
{
int data;
char c;
LinkList p,q;
q=head;
printf("请输入数据:");
do
{
scanf("%d",&data);
c=getchar();
p=(LinkList)malloc(sizeof(LNode));
if(p==NULL)
{
printf("空间分配失败\n");
return -1;
}
p->node=data;
p->next=q->next;
q->next=p;
q=p;
}
while(c!='\n');
return 0;
}
LinkList Reverse(LinkList head)
{
LinkList p,q,r;
p=head;
q=head->next;
head->next=NULL;
if(q->next!=NULL)
{
r=q->next;
q->next=p;
p=q;
q=r;
}
q->next=p;
head->next=q;
return head;
}
void Output(LinkList head)
{
LinkList p;
p=head->next;
while(p)
{
printf("%d ",p->node);
p=p->next;
}
}
int main()
{
LinkList head;
head=Head_Node();
CreateList(head);
Reverse(head);
Output(head);
system("pause");
return 0;
}