作者在 2010-04-28 20:09:16 发布以下内容
#include<stdio.h>
#include<conio.h>
#define OVERFLOW -2
#define OK 1
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*Linklist;
int initlist(LNode *L)
{ L=(LNode *)malloc(sizeof(LNode));
if(!L)exit(OVERFLOW);
L->next=NULL;
return OK;
}
void Creatlist(LNode *L ,int n)
{ LNode *p,*q;
int i;
q=L;
for(i=0;i<n;i++)
{
p=(LNode *)malloc(sizeof(LNode));
scanf("%d",&p->data);
q->next=p;
q=p;
}
p->next=NULL;
}
void Linklist_reverse(LNode *L)
{LNode *p,*q,*s;
p=L->next;q=p->next;s=q->next;p->next=NULL;
while(s->next!=NULL)
{
q->next=p;p=q;
q=s;s=s->next;
}
q->next=p;s->next=q;L->next=s;
}
void prinlist(LNode*L)
{ LNode *p;
p=L->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
LNode *L;
int n;
printf("the number you want enter:");
scanf("%d",&n);
initlist(L);
printf("Enter the number:");
Creatlist(L,n);
Linklist_reverse(L);
printf("the number of after nizhi:");
prinlist(L);
free(L);
#include<conio.h>
#define OVERFLOW -2
#define OK 1
typedef struct LNode
{
int data;
struct LNode *next;
}LNode,*Linklist;
int initlist(LNode *L)
{ L=(LNode *)malloc(sizeof(LNode));
if(!L)exit(OVERFLOW);
L->next=NULL;
return OK;
}
void Creatlist(LNode *L ,int n)
{ LNode *p,*q;
int i;
q=L;
for(i=0;i<n;i++)
{
p=(LNode *)malloc(sizeof(LNode));
scanf("%d",&p->data);
q->next=p;
q=p;
}
p->next=NULL;
}
void Linklist_reverse(LNode *L)
{LNode *p,*q,*s;
p=L->next;q=p->next;s=q->next;p->next=NULL;
while(s->next!=NULL)
{
q->next=p;p=q;
q=s;s=s->next;
}
q->next=p;s->next=q;L->next=s;
}
void prinlist(LNode*L)
{ LNode *p;
p=L->next;
while(p!=NULL)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
LNode *L;
int n;
printf("the number you want enter:");
scanf("%d",&n);
initlist(L);
printf("Enter the number:");
Creatlist(L,n);
Linklist_reverse(L);
printf("the number of after nizhi:");
prinlist(L);
free(L);