字符串左移,void *pszStringRotate(char *pszString, int nCharsRotate),比如ABCDEFG,移3位变DEFGABC,要求空间复杂度O(1),时间复杂度O(n)
有些做做法用了一些库函数,比如,memcpy,strcpy,大家也可以参考下
//字符串移位,
void LoopMove_right(char *p,int steps)//右移
{
char temp;
for (int i=0;i<steps;i++)
{
temp=p[strlen(p)-1]; //尾部 赋给缓冲区
for (int j=strlen(p)-2;j>-1;j--)
{
p[j+1]=p[j];
}
p[0]=temp; //尾部的字母付给头部
}
}
void LoopMove_left(char *p,int steps) //左移
{
char temp;
for (int i=0;i<steps;i++)
{
temp=p[0];
for (int j=0;j<strlen(p)-1;j++)
{
p[j]=p[j+1];
}
p[strlen(p)-1]=temp;
}
}
有些做做法用了一些库函数,比如,memcpy,strcpy,大家也可以参考下