插入排序算法实现

上传人:kms****20 文档编号:41167061 上传时间:2018-05-28 格式:DOC 页数:7 大小:31.50KB
返回 下载 相关 举报
插入排序算法实现_第1页
第1页 / 共7页
插入排序算法实现_第2页
第2页 / 共7页
插入排序算法实现_第3页
第3页 / 共7页
插入排序算法实现_第4页
第4页 / 共7页
插入排序算法实现_第5页
第5页 / 共7页
点击查看更多>>
资源描述

《插入排序算法实现》由会员分享,可在线阅读,更多相关《插入排序算法实现(7页珍藏版)》请在金锄头文库上搜索。

1、插入排序算法实现插入排序算法实现#include#include#include#include/#define MAX 10000#define END 20000/struct node int val;struct node *pre;struct node *next;/struct node *Bnode(struct node *p,int n);struct node *Insertsort(struct node *p,int flag);/int main(void)int i,sum,num,flag,mode;struct node *List = NULL;printf

2、(“Please choose the serial number of sort mode:n“);printf(“t1.input by yourself.n“);printf(“t2.input by the computer itself.n“);scanf(“%d“,if(mode = 2)printf(“Please input the total number needed to sortn“);scanf(“%d“,printf(“Please input the order of sort by number:n“);printf(“t1.升序n“);printf(“t2.降

3、序n“);scanf(“%d“,srand(unsigned)time(NULL);for(i = 0; i val = n;temp-pre = NULL;temp-next = NULL;p = temp;elseq = p;while(q-next != NULL)q = q-next;temp = (struct node *)malloc(sizeof(struct node);temp-val = n;temp-pre = q;temp-next = NULL;q-next = temp;return p;/struct node *Insertsort(struct node *

4、p,int flag)struct node *temp,*next;struct node *q,*q1;FILE *fp;int i = 0;flag = flag -1;fp = fopen(“F:Insertsort.csv“,“w“);temp = p;fprintf(fp,“初始数据t,“);while(temp != NULL)fprintf(fp,“%-5d,“,temp-val);temp = temp-next;fprintf(fp,“n“);fprintf(fp,“n“);temp = p;fprintf(fp,“趟数列标,“);while(temp != NULL)fp

5、rintf(fp,“%-5d,“,+i);temp = temp-next;fprintf(fp,“n“);/fprintf(fp,“-n“);i = 0;for(q = p-next; q != NULL; q = next)i+;temp = q1 = q;next = q-next;if(q1 -pre-val q1-val if(q1-next != NULL)q1-next-pre = q1-pre;q1 =q1-pre;while(q1-val temp-val if(q1 = NULL)temp-next = p;p-pre = temp;temp-pre = NULL;p =

6、temp;break;if(q1 != NULL)temp-next = q1-next;q1-next-pre = temp;q1-next = temp;temp-pre = q1;temp = p;fprintf(fp,“第%d 趟t,“,i);while(temp != NULL)fprintf(fp,“%-5d,“,temp-val);temp = temp-next;fprintf(fp,“n“);/*endfor*/fprintf(fp,“*n“);fprintf(fp,“n“);temp = p;fprintf(fp,“排序结果t,“);while(temp != NULL)fprintf(fp,“%-5d,“,temp-val);temp = temp-next;if(!flag)fprintf(fp,“(升序),“);elsefprintf(fp,“(降序),“);fprintf(fp,“n“);fclose(fp);system(“F:Insertsort.csv“);system(“del F:Insertsort.csv“);return p;

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号