📄 insert_node.c
字号:
#include<stdio.h>
struct node
{int data;
struct node * prior,*next;
};
main()
{int x,n,m;
struct node *h,*s,*p,*j,*f;
h=(struct node*)malloc(sizeof(struct node));
p=h;
printf("\nplease input an int number:\n");
scanf("%d",&x);
while(x!=-1)
{s=(struct node *)malloc(sizeof(struct node));
s->data=x;
p->next=s;
s->prior=p;
p=s;
printf("please input again:\n");
scanf("%d",&x);
} h->next->prior=NULL;
h=h->next;
p->next=NULL;
printf("the built listtype s:\n");
f=h;
while(f->next!=NULL)
{printf("%d",f->data);printf(" ");
f=f->next;
}
if(f->next==NULL)
printf("%d",f->data);
printf("\nplease input an int number you want to search:\n");
scanf("%d",&n);
j=h;
while(h->data!=n&&h->next!=NULL)
h=h->next;
if(h->data==n)
{m=h->prior->data;
h->prior->data=n;
h->data=m;
}
else
printf("searching failed,so the listtype is put as before:\n");
printf("the sorted number is:\n");
while(j->next!=NULL)
{printf("%d",j->data); printf(" ");
j=j->next;
}
if(j->next==NULL)
printf("%d",j->data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -