链表插入
#include <stdio.h>
#include <stdlib.h>
//這里創建一個結構體用來表示鏈表的結點類型
struct node{int data;struct node *next;};
int main()
{struct node *head,*p,*q,*t;int i,n,m,a;scanf("%d",&n);head = NULL;for(i=1;i<=n;i++){scanf("%d",&a);//建立p=(struct node *)malloc(sizeof(struct node));p->data=a;p->next=NULL;if(head==NULL)head=p;elseq->next=p;q=p;}scanf("%d",&m);//插入t=head;while(t!=NULL){if(t->next->data > m){p=(struct node *)malloc(sizeof(struct node));p->data=m;p->next=t->next;t->next=p;break;}t=t->next;}t=head;//輸出while(t!=NULL){printf("%d ",t->data);t=t->next;}getchar();getchar();return 0;
}
?
轉載于:https://www.cnblogs.com/QuantumGhost/p/6070385.html
總結
- 上一篇: JavaScript 身份证号有效验证详
- 下一篇: 改变软件开发者的形象,增加多样性