欢迎来到天天文库
浏览记录
ID:61464132
大小:36.50 KB
页数:12页
时间:2021-02-02
《快速排序堆排序基数排序折半插入排序起泡排序选择排序插入排序等九种排序方法.doc》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、#include#include#includelongintcompare=0;longintswap=0;//--------------------------------------------1、起泡排序法-----------------------------------------------voidqipaosort(intsize){compare=swap=0;inti,j;int*a=(int*)malloc(sizeof(int)*size);inttemp;for(i=0;i2、rand()%1000;}for(i=0;ia[j]){swap++;temp=a[i];a[i]=a[j];a[j]=temp;}}for(i=0;i3、intf("写入出错");exit(0);}}fclose(fp);*/free(a);printf("起泡排序的比较次数为:%ld",compare);printf("起泡排序的交换次数为:%ld",swap);printf("起泡排序占用的空间为:%d",sizeof(int)*size);printf("");/*FILE*fp2;fp2=fopen("起泡排序.txt","rb");for(i=0;i4、-------------------2、选择排序法------------------------------------------voidxuanzesort(intsize){compare=swap=0;inti,j,k;int*a=(int*)malloc(sizeof(int)*size);inttemp;for(i=0;i5、];a[i]=a[k];a[k]=temp;}}/*FILE*fp;if((fp=fopen("选择排序.txt","wb"))==NULL){printf("打开文件失败");exit(0);}int*b=a;for(i=0;i6、次数为:%ld",compare);printf("选择排序的交换次数为:%ld",swap);printf("选择排序占用的空间为:%d",sizeof(int)*size);printf("");}//--------------------------------------------3、二叉树排序----------------------------------------------------------structtree{intdata;structtree*left;structtree*right;}*head;voidread(structtree*7、newtemp){if(newtemp!=NULL){read(newtemp->left);printf("%4d",newtemp->data);read(newtemp->right);}}voiderchashusort(intsize){compare=swap=0;structtree*look;inti;for(i=0;i
2、rand()%1000;}for(i=0;ia[j]){swap++;temp=a[i];a[i]=a[j];a[j]=temp;}}for(i=0;i3、intf("写入出错");exit(0);}}fclose(fp);*/free(a);printf("起泡排序的比较次数为:%ld",compare);printf("起泡排序的交换次数为:%ld",swap);printf("起泡排序占用的空间为:%d",sizeof(int)*size);printf("");/*FILE*fp2;fp2=fopen("起泡排序.txt","rb");for(i=0;i4、-------------------2、选择排序法------------------------------------------voidxuanzesort(intsize){compare=swap=0;inti,j,k;int*a=(int*)malloc(sizeof(int)*size);inttemp;for(i=0;i5、];a[i]=a[k];a[k]=temp;}}/*FILE*fp;if((fp=fopen("选择排序.txt","wb"))==NULL){printf("打开文件失败");exit(0);}int*b=a;for(i=0;i6、次数为:%ld",compare);printf("选择排序的交换次数为:%ld",swap);printf("选择排序占用的空间为:%d",sizeof(int)*size);printf("");}//--------------------------------------------3、二叉树排序----------------------------------------------------------structtree{intdata;structtree*left;structtree*right;}*head;voidread(structtree*7、newtemp){if(newtemp!=NULL){read(newtemp->left);printf("%4d",newtemp->data);read(newtemp->right);}}voiderchashusort(intsize){compare=swap=0;structtree*look;inti;for(i=0;i
3、intf("写入出错");exit(0);}}fclose(fp);*/free(a);printf("起泡排序的比较次数为:%ld",compare);printf("起泡排序的交换次数为:%ld",swap);printf("起泡排序占用的空间为:%d",sizeof(int)*size);printf("");/*FILE*fp2;fp2=fopen("起泡排序.txt","rb");for(i=0;i4、-------------------2、选择排序法------------------------------------------voidxuanzesort(intsize){compare=swap=0;inti,j,k;int*a=(int*)malloc(sizeof(int)*size);inttemp;for(i=0;i5、];a[i]=a[k];a[k]=temp;}}/*FILE*fp;if((fp=fopen("选择排序.txt","wb"))==NULL){printf("打开文件失败");exit(0);}int*b=a;for(i=0;i6、次数为:%ld",compare);printf("选择排序的交换次数为:%ld",swap);printf("选择排序占用的空间为:%d",sizeof(int)*size);printf("");}//--------------------------------------------3、二叉树排序----------------------------------------------------------structtree{intdata;structtree*left;structtree*right;}*head;voidread(structtree*7、newtemp){if(newtemp!=NULL){read(newtemp->left);printf("%4d",newtemp->data);read(newtemp->right);}}voiderchashusort(intsize){compare=swap=0;structtree*look;inti;for(i=0;i
4、-------------------2、选择排序法------------------------------------------voidxuanzesort(intsize){compare=swap=0;inti,j,k;int*a=(int*)malloc(sizeof(int)*size);inttemp;for(i=0;i5、];a[i]=a[k];a[k]=temp;}}/*FILE*fp;if((fp=fopen("选择排序.txt","wb"))==NULL){printf("打开文件失败");exit(0);}int*b=a;for(i=0;i6、次数为:%ld",compare);printf("选择排序的交换次数为:%ld",swap);printf("选择排序占用的空间为:%d",sizeof(int)*size);printf("");}//--------------------------------------------3、二叉树排序----------------------------------------------------------structtree{intdata;structtree*left;structtree*right;}*head;voidread(structtree*7、newtemp){if(newtemp!=NULL){read(newtemp->left);printf("%4d",newtemp->data);read(newtemp->right);}}voiderchashusort(intsize){compare=swap=0;structtree*look;inti;for(i=0;i
5、];a[i]=a[k];a[k]=temp;}}/*FILE*fp;if((fp=fopen("选择排序.txt","wb"))==NULL){printf("打开文件失败");exit(0);}int*b=a;for(i=0;i6、次数为:%ld",compare);printf("选择排序的交换次数为:%ld",swap);printf("选择排序占用的空间为:%d",sizeof(int)*size);printf("");}//--------------------------------------------3、二叉树排序----------------------------------------------------------structtree{intdata;structtree*left;structtree*right;}*head;voidread(structtree*7、newtemp){if(newtemp!=NULL){read(newtemp->left);printf("%4d",newtemp->data);read(newtemp->right);}}voiderchashusort(intsize){compare=swap=0;structtree*look;inti;for(i=0;i
6、次数为:%ld",compare);printf("选择排序的交换次数为:%ld",swap);printf("选择排序占用的空间为:%d",sizeof(int)*size);printf("");}//--------------------------------------------3、二叉树排序----------------------------------------------------------structtree{intdata;structtree*left;structtree*right;}*head;voidread(structtree*
7、newtemp){if(newtemp!=NULL){read(newtemp->left);printf("%4d",newtemp->data);read(newtemp->right);}}voiderchashusort(intsize){compare=swap=0;structtree*look;inti;for(i=0;i
此文档下载收益归作者所有