好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C实例编程-C语言链表的创建与排序.docx

4页
  • 卖家[上传人]:汽***
  • 文档编号:545228819
  • 上传时间:2023-12-17
  • 文档格式:DOCX
  • 文档大小:11.93KB
  • / 4 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • C实例编程:C语言链表的创建与排序#include  typedef struct struct {  int value;  struct struct *next;  }ts;  main()  {  #define n 9  int a[n],i;  ts *head,*p;  ts *createlink(int *,int);  void sort(ts **);  randomize();  for(i=0;i a=random(9);  head=createlink(a,n);  for(p=head;p;p=p->next)  printf(\“%-2d\“,p->value);  putchar(\’\\n\’);  sort(  for(p=head;p;p=p->next)  printf(\“%-2d\“,p->value);  getchar();  }  void sort(ts **h) /* 选择排序算法 */  {  ts *h1,*p,*q,*r,*s;  h1=p=(ts *)malloc(sizeof(ts));  p->next=*h;  while(p->next) {  q=p->next;  r=p;  while(q->next) {  if(q->next->valuenext->value)  r=q;  q=q->next;  }  if(r!=p) {  s=r->next;  r->next=s->next;  s->next=p->next;  p->next=s;  }  p=p->next;  }  *h=h1->next;  free(h1);  }  ts *createlink(int *a,int n)  {  int i;  ts *h,*p;  h=null;  for(i=n;i>0;i--) {  p=(ts *)malloc(sizeof(ts));  p->value=a[i-1];  p->next=h;  h=p;  }  return h;  }。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.