c sort
来源:互联网 发布:淘宝店铺转化率低 编辑:程序博客网 时间:2024/06/06 14:18
1 sort.c
#include<stdio.h>#define MAX 1000void quicksort(int arrar[],int low,int high){ int key=arrar[low]; int l=low; int h=high; if(low >= high) return; while(low < high) { while(low<high && arrar[high]>=key) { high--; } arrar[low]=arrar[high]; while(low<high && arrar[low]<key) { low++; } arrar[high]=arrar[low]; } arrar[low]=key; quicksort(arrar,l,low-1); quicksort(arrar,high+1,h);}void bubblesort(int arrar[],int count){ int i,j,tmp; for(i=0;i<count;i++) { for(j=0;j<count-1-i;j++) { if(arrar[j]>arrar[j+1]) { tmp=arrar[j]; arrar[j]=arrar[j+1]; arrar[j+1]=tmp; } } }}void selectsort(int arrar[],int count){ int tmp,i,j,min; for(i=0;i<count;i++) { min=i; for(j=i+1;j<count;j++) { if(arrar[min]>arrar[j]) min=j; } if(min!=i) { tmp=arrar[i]; arrar[i]=arrar[min]; arrar[min]=tmp; } }}void selectsort_2(int arrar[],int count){ int i,j,tmp; for(i=0;i<count;i++) { for(j=i+1;j<count;j++) { if(arrar[i]>arrar[j]) { tmp=arrar[i]; arrar[i]=arrar[j]; arrar[j]=tmp; } } }}void insertsort(int arrar[],int count){ int i,j,tmp,k; for(i=0;i<count;i++) { tmp=arrar[i]; for(j=i;j>0;j--) { if(tmp<arrar[j-1]) arrar[j]=arrar[j-1]; else break; } arrar[j]=tmp; printf("经过第%d趟排序的结果:\n",i); for(k=0;k<count;k++) printf("%-4d",arrar[k]); printf("\n"); }}int main(){ int count,i,j; int array[MAX]; printf("输入数据的个数:\n"); scanf("%d",&count); printf("输入数据:\n"); for(i=0;i<count;i++) { scanf("%d",&array[i]); } printf("数据的个数%d\n",count); printf("数组的原始序列:\n"); for(i=0;i<count;i++) { printf("%-4d",array[i]); } printf("\n"); quicksort(array,0,count-1);// insertsort(array,count);// selectsort_2(array,count);// selectsort(array,count);// bubblesort(array,count); printf("排序后的结果:\n"); for(i=0;i<count;i++) { printf("%-4d",array[i]); } printf("\n"); return 0;}
2 search.h
#include<stdio.h>#define MAXSIZE 10int search_f(int array[],int low,int high,int data){ int l,h,m; if(low>high) return -1; l=low; h=high; m=(l+h)/2; if(array[m]==data) return m; else if(array[m]<data) search_f(array,m+1,h,data); else search_f(array,l,m-1,data);}int search(int array[],int data){ int l,h,m; l=0; h=MAXSIZE; while(l<h) { m=(l+h)/2; if(array[m]==data) return m; else if(array[m]<data) l=m+1; else h=m-1; } return -1;}int main(){ int array[MAXSIZE]; int i,data; printf("请输入%d个数字:\n",MAXSIZE); for(i=0;i<MAXSIZE;i++) { scanf("%d",&array[i]); } printf("请输入要查找的数据:\n"); scanf("%d",&data); i=search_f(array,0,MAXSIZE-1,data); if(i!=-1) printf("查找的数据=%d\n",array[i]); else printf("没找到查找的数据\n"); return 0;}
0 0
- Sort-C
- C++sort
- c sort
- SORT BY C
- linux sort uniq -c
- linux sort uniq -c
- C++~~~std::sort
- 【C++】STL的sort
- C ++ sort()与stable_sort()
- C++sort 函数用法
- C++: selection sort
- C语言--sort
- C++sort 函数用法
- C ++ sort()与stable_sort()
- C#ArrayList-sort
- C++STL:sort/qsort
- C++sort 函数用法
- c编写 Topological Sort
- 有用的博客地址
- HTML5学习(四)—2
- 音视频开发——iOS音频录制(六)
- hibernate参数设置
- 扩展欧几里得各类问题模板
- c sort
- git 常用命令集锦
- 文本文件大数据查询
- 虚拟函数是否应该被声明仅为private/protected?
- >LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
- ASP.NET之Cookie(坑爹的Response.Cookies.Remove)
- WideCharToMultiByte和MultiByteToWideChar函数的用法
- 数据结构实验之查找四:二分查找
- Busybox简介