📄 倒置2.c
字号:
#define NULL 0
#include "stdio.h"
#include "stdlib.h"
typedef int datatype;
typedef struct node
{ datatype data;
struct node *next;
} linklist;
linklist *head,*p,*q;
int i;
linklist *CREAT()
{ int ch;
linklist *s,*r;
head=(struct node*)malloc(sizeof(linklist));
r=head;
printf("链表:\n");
scanf("%d",&ch);
while(ch!=NULL)
{ s=(struct node*)malloc(sizeof(linklist));
s->data=ch;
r->next=s;
r=s;
printf("%d\t",s->data);
scanf("%d",&ch);
}
r->next=NULL;
return (head);
}
void INVERT(linklist *s)
{ linklist *a,*b,*c;
a=s;
b=a->next;
while(b!=NULL)
{ c=b->next;
b->next=a;
a=b;
b=c;
}
s->next=NULL;
s=a;
printf("倒置后的链表为:\n");
while(s->next!=NULL)
{ printf("%d\t",s->data);
s=s->next;
}
}
int main(int argc, char* argv[])
{
p=CREAT();
printf("\n");
INVERT(head);
printf("\n");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -