#include <stdio.h>
#include <stdlib.h>
void reverse(char *array, int begin, int end)
{
char tmp;
while (begin < end)
{
tmp = array[begin];
array[begin] = array[end];
array[end] = tmp;
begin++;
end--;
}
}
void rotate(char *array, int len, int nrt)
{
reverse(array, 0, nrt - 1);
reverse(array, nrt, len - 1);
reverse(array, 0, len - 1);
}
int main(int argc, char **argv)
{
char str[] = "abcdefgh";
rotate(str, 8, 4);
printf("rotate: %s\n", str);
return 0;
}
字符串旋转算法 -- 求逆
最新推荐文章于 2018-10-24 21:22:45 发布