//原文:
//
// 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 4.4
- [Cracking the Coding Interview] 4.5 Validate BST
- Cracking the Coding Interview(Stacks and Queues)
- Cracking the coding interview--Q2.3
- 《Cracking the Coding Interview》——第6章:智力题——题目2
- crack the coding interview
- Cracking the coding interview--问题与解答
- Cracking the coding interview--Q1.6
- Cracking the coding interview--Q1.3
- Cracking the coding interview--Q18.1