📄 4_6.txt
字号:
#include<stdio.h>
typedef struct node{
char data;
struct node *next;
}clink;
createclink(clink **h,char *s)
{
clink *q,*p;
int i=0;p=*h;
while(s[i]!='\0' && s[i]!='\n'){
q=(clink *)malloc(sizeof(clink));
q->data=s[i];
q->next=NULL;
p->next=q;
p=q;
i++;
}
}
adjust(clink *h)
{
clink *h1,*h2,*t,*s,*p,*q;int i=1;
h1=h;t=h;p=h->next;h2=NULL;
while(p){
q=p->next;
if(i%2!=0){
if(h2==NULL){
h2=p;
s=p;
}
else{
s->next=p;
s=p;}
}
else{
t->next=p;
t=p;}
i++;
p=q;
}
t->next=h2;
s->next=NULL;
}
main()
{
clink *h,*p;char *s;
h=(clink *)malloc(sizeof(clink));
h->next=NULL;
printf("请输入字符串:\n");
gets(s);
createclink(&h,s); /*建立单链表*/
adjust(h);
p=h->next;
while(p){
printf("%c ",p->data);
p=p->next;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -