?? indert.c
字號:
#include<stdio.h>#include<stdlib.h>#define LEN sizeof (struct stu)typedef struct stu{ int num; int age; struct stu *next;}TYPE;TYPE *insert1(int n){ struct stu *head,*pf,*pb; int i; for (i=0;i<n;i++) { pb=(TYPE*)malloc(LEN); printf("input Number and Age\n"); scanf("%d%d",&pb->num,&pb->age); if(i==0) pf=head=pb; else pf->next=pb; pb->next=NULL; pf=pb; } return(head);}TYPE *insert(TYPE *pi,TYPE *pj){ TYPE *pf,*pb,*ps,*p; pb=pi; ps=pj; while(ps!=NULL) { while(ps->num>pb->num&&(pb->next!=NULL)) { pf=pb; pb=pb->next; } if(ps->num<=pb->num) { if(pi==pb) pi=ps; else pf->next=ps; p=ps->next; ps->next=pb; } else { pb->next=ps; p=ps->next; ps->next=NULL; //ps->next=NULL; } ps=p; } return (pi); }void delete_stu(TYPE *head){ TYPE *p=head; TYPE *q; while(p!=NULL) { q=p->next; free(p); p=q; }}int main(){ TYPE *p,*q,*s; int n,m; scanf("%d%d",&n,&m); p=insert1(n); q=insert1(m); s=insert(p,q); while(s!=NULL) { printf("%d\t%d\n",s->num,s->age); s=s->next; } delete_stu(p); delete_stu(q); getchar(); getchar(); return 0; }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -