首页 串操作和排序 共10个

串操作和排序 共10个

举报
开通vip

串操作和排序 共10个 1. strcat strlen char *MyStrCat(char *dest, const char *src); size_t MyStrLen(const char *str); char *MyStrCat(char *dest, const char *src) { char *pch=dest; if(NULL ==pch) return dest; for( ;'\0' != *pch ;pch++) ; whi...

串操作和排序 共10个
1. strcat strlen char *MyStrCat(char *dest, const char *src); size_t MyStrLen(const char *str); char *MyStrCat(char *dest, const char *src) { char *pch=dest; if(NULL ==pch) return dest; for( ;'\0' != *pch ;pch++) ; while( *pch++ = *src++ ); return dest; } size_t MyStrLen(const char *str) { int len=0; if(NULL == str) return len; for(len=0; '\0' != *str; str++) len++; return len; } 2. strcmp int MyStrCmp(const char *, const char *); int MyStrCmp(const char *str1, const char *str2) { unsigned int len1=0,len2=0; char *pStr1=str1; char *pStr2=str2; for(len1=0; '\0'!=*pStr1; pStr1++){ len1++; } for(len2=0; '\0'!=*pStr2; pStr2++){ len2++; } if(len1 != len2){ return len1-len2; } while('\0' != *str1) { if(*str1 != *str2) break; else { str1++; str2++; } } if('\0' == *str1) return len1-len2; else return (int)*str1-*str2; } 3. strstr #include #define EN_EQU 1 #define NOT_EQ 0 char *MyStrStr(const char *haystack, const char *needle); char *MyStrStr(const char *haystack, const char *needle){ int n,m; int x,k; int pre; int PIK=0; int r; int flag=NOT_EQ; if(NULL == haystack || NULL == needle) return NULL; n=strlen(haystack); m=strlen(needle); if(m<0 || n<0 || n a[j+1]) { temp = a[j+1]; a[j+1] = a[j]; a[j] = temp; flag=FALSE; } } if(TRUE == flag) break; } return; } 6. QuickSort void Quick(int a[], int low, int high); int Partition(int a[], int low, int high); void Quick(int a[], int low, int high) { int pivot; if(low= pivotKey) high--; if(low < high) a[low] = a[high]; while(low < high && a[low]<=pivotKey) low++; if(low < high) a[high] = a[low]; } a[low]=temp; return low; } 7. SelectionSort void SelectionSort(int a[],int size); void SelectionSort(int a[],int size) { int i,j; int min,temp; for(i=0; i=0; i--) PercUpDown(a,i,size); for(i=size-1; i>0; i--) { Swap(&a[0],&a[i]); PercUpDown(a,0,i); } } void PercUpDown(Int a[], int percPos, int n) { int childPos; Int temp; for(temp= a[percPos]; LeftChild(percPos) a[childPos]) childPos++; if(temp < a[childPos]) a[percPos]=a[childPos]; else break; } a[percPos]=temp; } void Swap(Int *a, Int *b) { Int tmp=*a; *a=*b; *b=tmp; } 9. ShellSort void ShellSort(Int a[], int size); void ShellSort(Int a[], int size) { int i; int j; int temp; int gap=0; while(gap<=size){ gap=gap * 3 + 1; } while(gap>0) { for ( i=gap; i=0 && temp0 && temp
本文档为【串操作和排序 共10个】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
下载需要: 免费 已有0 人下载
最新资料
资料动态
专题动态
is_071663
暂无简介~
格式:pdf
大小:111KB
软件:PDF阅读器
页数:8
分类:互联网
上传时间:2011-12-08
浏览量:14