C语言建立链表删除插入等操作!.docVIP

  • 1
  • 0
  • 约2.33千字
  • 约 3页
  • 2018-05-05 发布于河南
  • 举报
C语言建立链表删除插入等操作!

#include stdio.h #include stdlib.h #define LEN sizeof(struct ss) typedef struct ss *pointer; struct ss { int num; int score; pointer next; }; int n=0; struct ss *link(void) { struct ss *p,*pp,*head; head=NULL; p=pp=(struct ss *)malloc(LEN); printf(Build linked:\n); scanf(%d%d,p-num,p-score); while(p-num!=0) { n++; if(n==1) head=p; else pp-next=p; pp=p; p=(struct ss *)malloc(LEN); scanf(%d%d,p-num,p-score); } pp-next=NULL; return head; } void print(struct ss *head) { struct ss *pq; pq=head; while(pq!=NULL) { printf(%30d %d\n,pq-num,pq-score); pq=pq-next; } printf(%28dpoints!\n,n); } struct ss *del(struct ss *head) { int del_num; struct ss *p1,*p2; printf(Input del_num:); scanf(%d,del_num); if(head==NULL) printf(Empty!no found!\n); else { p1=head; p2=head; while((del_num!=p1-num)(p1-next!=NULL)) {p2=p1;p1=p1-next;} if(del_num==p1-num) { if(p1==head) head=p1-next; else p2-next=p1-next; n--; printf(del_num:%d\n,del_num); } else printf(No found %d\n,del_num); } return head; } struct ss *insert(struct ss *head) { struct ss *q1,*q2,*p0; q1=head; q2=head; p0=(struct ss *)malloc(LEN); printf(Input insert num and score:); scanf(%d%d,p0-num,p0-score); if(head==NULL) {head=p0;p0-next=NULL;} else { while((p0-numq1-num)(q1-next!=NULL)) {q2=q1;q1=q1-next;} if(p0-num=q1-num) { if(q1==head) head=p0; else q2-next=p0; p0-next=q1; } else {q1-next=p0;p0-next=NULL;} } printf(Insert num:%d %d\n,p0-num,p0-score); n++; return head; } int main() { struct ss *head; int x; head=NULL; while(1) { printf(4.display\n); printf(1.delete\n); printf(3.insert\n); printf(6.exit\n); printf(9.build\n); printf(Input:); scanf(%d,x); switch(x) { case 4 : print(head); continue;

文档评论(0)

1亿VIP精品文档

相关文档