1.2

来源:互联网 发布:网络电视盒子推荐 编辑:程序博客网 时间:2024/06/12 01:06

Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)

void reverse(char* str){if(str==NULL)    return;int i=0,j=strlen(str)-1;while(i<j){int tmp=str[i];str[i]=str[j];str[j]=tmp;//forget i++,j-- when writing on paperi++;j--;}}
在纸上,看似简单的代码还是总出问题:我忘记了i++,j--,将纸上的程序输入到计算机中时导致死循环

原创粉丝点击