- //选择排序算法,先选出一个最小的作为临时最小变量,通过比较后再交换
- void selectsort(int a[],int n)
- {
- int i,j,small;
- int temp;
- for(i=0;i<n;i++)
- {
- i = small;
- for(j=i+1;j<n-1;j++)
- {
- if(a[samll]>a[j])
- small = j;
- if(i!=small)
- {
- temp = a[i];
- a[i] = a[i+1];
- a[i+1] = temp;
- }
- }
- }
- //插入排序
- void insertsort(int a[],int n)
- {
- int i,j,temp;
- for(i=0;i<n-1;i++)
- {
- temp = a[i+1];
- j = i;
- while(temp<a[j])
- {
- a[j+1] = a[j];
- j--;
- }
- a[j+1] = temp;
- }
- }
- //快速排序
- void QuickSort(int a[],int low,int high)
- {
- int temp;
- int i = low,j = high;
- temp = a[low];
- while(i<j&&temp<a[j]) //在数组的右边扫描,查找比temp小的第一个数,进行交换
- j--;
- if(i<j)
- {
- a[i] = a[j];
- i++
- }
- while(i<j&&temp>a[i]) //在数组的左边扫描,查找比temp大的第一个数,进行交换
- i++;
- if(i<j)
- {
- a[j] = a[i];
- j--;
- }
- a[i] = temp;
- if(low<i)
- QuickSort(a,low,i-1); //递归实现全部排序
- if(i<high)
- QuickSort(a,j+1,high);
- }
- 三次握手、四次断开
- char *my_strcat(char *des,char *src)
- {
- char *temp = des;
- if(des==NULL src1==NULL)
- {
- printf("Error!\\n");
- }
- while(*des)
- {
- *des++;
- }
- while(*src)
- {
- *des++ = *src++;
- }
- *des = '\\0';
- return temp;
- }
- char *my_strcpy(char *des,const char *src)
- {
- char *temp = des;
- if(des==NULL src1==NULL)
- {
- printf("error!\\n");
- }
- while(*des)
- {
- *des++ = *src++;
- }
- *des = '\\0';
- return temp;
- }
- //该片段来自于http://www.codesnippet.cn/detail/260520149670.html
来源: http://www.codesnippet.cn/detail/260520149670.html