使用C/C++编写函数,实现字符串反转,要求不使用任何系统函数,且时间复杂度最小,函数原型:char* reverse_str(char* str)。
char* reverse_str(char* str){
char* begin=str;
char* end=str;
char* tmp=NULL;
if(!str)
return str;
while(*(end++)!='\0'){
}
end--;//跳到字符串最后一个字符
while(begin *tmp=*begin; *begin=*end; *end=*tmp; begin++; end-; } return str; }
*tmp=*begin;
*begin=*end;
*end=*tmp;
begin++;
end-;