算法

2017-03-02  本文已影响0人  壳克

 char* str_cpy(char* dest,char*src){

if(dest ==NULL|| src ==NULL) {

returnNULL;

}

char*strdest = dest;

char*strSrc = src;

while( (*strdest++ = *strSrc++) !='\0');

returnstrdest;

}

void* mem_cpy(void*dest,void*src,size_tsize){

if(dest ==NULL|| src ==NULL)

returnNULL;

char* temp_des = (char*)dest;

char* temp_src = (char*)src;

while( size-- >0) {

*temp_des++ = *temp_src++;

}

returntemp_des;

}

-(void)insertSort{

intx[] = {4,3,7,8,45,3,5,2,99,1};

for(inti=1; i

for(intj = i; j>0&& x[j-1]>x[j];j--) {

inttemp = x[j];

x[j]=x[j-1];

x[j-1] = temp;

}

}

for(inti =0; i

printf(" %d",x[i]);

}

}

voidquick_sort(int* s,intl,intr)

{

if(l < r)

{

/*

72 6 57 88 60 42 83 73 48 85

*/

//Swap(s[l], s[(l + r) / 2]); //将中间的这个数和第一个数交换参见注1

inti = l, j = r, t = s[l];

while(i < j)

{

while(i < j && s[j] >= t)//从右向左找第一个小于t的数

j--;

if(i < j)

s[i++] = s[j];

while(i < j && s[i] < t)//从左向右找第一个大于等于t的数

i++;

if(i < j)

s[j--] = s[i];

}

s[i] = t;

quickSort(s, l, i -1);//递归调用

quickSort(s, i +1, r);

}

}

上一篇 下一篇

猜你喜欢

热点阅读