void reverse( char *left, char *right)
{
char temp = 0;
assert(left);
assert(right);
while ( left < right)
{
temp = *left;
*left = *right;
*right = temp;
left++;
right--;
}
}
void leftShift( char *dest,int m) //左旋k个字符串
{
assert(dest);
int len = strlen(dest);
reverse(dest,dest+m-1); //前m个字符逆置
reverse(dest+m, dest+len- 1); //后面的字符逆置
reverse(dest, dest + len - 1);//整体逆置
}
int compareString( const char *dest,const char *src)//字符串包含
{
assert(dest);
assert(src);
int store[58] = {0};
int i = 0;
while (*src)
{
store[*src - 65] = 1;
src++;
}
while (*dest)
{
store[*dest - 65] = 0;
dest++;
}
for (i = 0; i < 58; i++)
{
if ( store[i] != 0)
{
return 0;
}
if (i == 57)
{
return 1;
}
}
}
//int compareString(const char *dest, const char *src)
//{
// assert(dest);
// assert(src);
//
// int n_src = strlen(src);
// int n_dest = strlen(dest);
//
// int store[58] = { 0 };
// int i = 0;
// for (i = 0; i < n_src;i++)
// {
// store[src[i]-65] = 1;
// }
// for (i = 0; i < n_dest; i++)
// {
// store[dest[i] - 65] = 0;
// }
// for (i = 0; i < 58; i++)
// {
// if (store[i] != 0)
// {
// return 0;
// }
// if (i == 57)
// {
// return 1;
// }
// }
//}
int maxSum(int arr[],int n) //求子数组的最大和
{
int max = *arr;
int sum = 0;
int i =0;
for (i = 0; i < n;i++)
{
if ( sum >=0)
{
sum += arr[i];
}
else
{
sum = arr[i];
}
if (sum > max)
{
max = sum;
}
}
return max;
}
int checkSys() //检测系统大小端,1,小端;0,大端
{
int num = 1;
return * (char*)#
}
int my_strlen(const char *dest) //求字符串长度
{
assert(dest);
const char *pdest = dest;
while (*pdest++)
{
NULL;
}
return pdest - dest - 1;
}
size_t my_strlen(const char *dest)
{
assert(dest);
const char *pdest = dest;
size_t count = 0;
while (*pdest++)
{
count++;
}
return count;
}
size_t my_strlen(const char *dest)
{
assert(dest);
if (*dest == ‘\0‘)
{
return 0;
}
return ( 1 + my_strlen(dest + 1) );
}
size_t my_strlen(const char *dest)
{
assert(dest);
const char *pdest = dest;
while (*pdest++)
{
NULL;
}
return (pdest - dest -1);
}
char* my_strcat( char *dest,const char *src) //字符串的连接
{
assert(dest);
assert(src);
char *ret = dest;
while (*dest)
{
dest++;
}
while (*dest++ = *src++)
{
NULL;
}
return ret;
}
int my_strcmp(const char *str1,const char *str2)// 字符串的比较
{
assert(str1);
assert(str2);
while ( *str1 == *str2 )
{
if ( *str1 == ‘\0‘)
{
return 0;
}
str1++;
str2++;
}
return (*str1 - *str2);
}
char * my_strcpy(char *dest,const char *src) //字符串的拷贝
{
assert(dest);
assert(src);
char *ret = dest;
while ( *dest++ = *src++)
{
NULL;
}
return ret;
}
char * my_strstr(const char *dest,const char *src) //查找源字符串在目的字符串中的位置
{
assert(dest);
assert(src);
const char *pdest = dest;
const char *psrc = src;
const char *s1 = NULL;
const char *s2 = NULL;
while (*pdest)
{
s1 = pdest;
s2 = psrc;
while ( (*s1!=‘\0‘) && (*s2!=‘\0‘)&&(*s1 == *s2))
{
s1++;
s2++;
}
if ( *s2 == ‘\0‘)
{
return (char *)pdest;
}
pdest++;
}
return NULL;
}
void *my_memmove( void *dest,const void *src,size_t count)//memmove实现
{
assert(dest);
assert(src);
char *ret = (char *) dest;
char *pdest = (char *) dest;
const char *psrc = (char *)src;
if ( (pdest >psrc) && pdest<(psrc+count))
{
while (count--)
{
*(pdest + count) = *(src + count); //内存重叠拷贝
}
}
else
{
while (count--)
{
*pdest++ = *psrc++;
}
}
return ret;
}