原题描述
用C或者C++实现void reverse(char *str)函数,即反转一个以null结尾的字符串
算法
Idea:
- 由于null结尾,不能使用strlen获取字符长度,——>先找到结尾字符的指针
- 从头——>中<——尾 进行交换,直到尾指针≤头指针,结束程序
Algo:
定义尾指针 = 头指针
while 遍历到尾部,并修改尾指针
定义用于交换的中间变量
while (str > end):
	三步交换,并str++,end--;
C++代码
void reverse(char *str) {
  char *end = str;
  while (*end) {
    end++;
  }
  end--;
  char tp;
  while (str < end) {
    tp = *str;
    *str++ = *end;
    *end-- = tp;
  }
}
Bug Free Procedure
- 2017.01.15 细节错误
    - 在循环遍历尾指针的时候没有在结束的时候自减一位
 
- 2017.01.16 Bingo!!!一次性AC