//原文:
//
// Write code to reverse a C-Style String. (C-String means that “abcd” is represented as five characters, including the null character.)
//
// 从前向后交换,到中间为止 #include <iostream>
using namespace std;
void mSwap(char &a, char &b)
{
char c=a;
a=b;
b=c;
}
void mReverse(char *str)
{
if (str == NULL)
{
return;
}
int size = strlen(str);
for (int i =0;i< size/2; i++)
{
mSwap(str[i], str[size-1-i]);
}
}
int main()
{
char s[] = "abcdefg";
cout << s <<endl;
mReverse(s);
cout << s <<endl;
return 0;
}
相关文章
- Cracking the coding interview--Q18.1
- Cracking the coding interview 第一章问题及解答
- 《Cracking the Coding Interview》读书笔记
- Cracking the coding interview
- 《Cracking the Coding Interview》——第2章:链表——题目7
- "Coding Interview Guide" -- 数组的partition调整
- Cracking The Coding Interview4.3
- Cracking The Coding Interview 1.8
- 《Cracking the Coding Interview 》之 二叉树的创建 与 遍历(非递归+递归version)
- 《Cracking the Coding Interview》——第14章:Java——题目5