看了各大IT公司2012校园招聘笔试面试整理中的《写一个字符串逆序的程序,时间复杂度和空间复杂度最低,效率越高越好。》这道题不知道我这种做法怎么样?
#include<stdio.h>
#include<string.h>void turnover(char *source);
int main()
{
char s[15];
strcpy(s, "goodluck");
turnover(s);
printf("%s\n",s);
return 0;
}
void turnover(char *source)
{
char* top,*bottom,x;
int len = strlen(source);
int i = 0;
int time = len/2;
while(time)
{
top=(source+i);
bottom=(source+len-1);
if(top == bottom)
return ;
x=*bottom;
*bottom=*top;
*top=x;
i++;
len--;
time--;
}
return;
}