将字符串字符顺序反转:
#include <iostream>
using namespace std;
void Reverse( char *pBegin, char *pEnd )
{
if( pBegin == NULL || pEnd == NULL )
return;
while( pBegin < pEnd )
{
char tmp = *pBegin;
*pBegin = *pEnd;
*pEnd = tmp;
pBegin++, pEnd--;
}
}
void Test( char *testName, char *input, char *expectedResult )
{
if( testName != NULL)
cout << testName << " begins: " << endl;
if( input == NULL )
return;
char *pBegin = input;
char *pEnd = input; //暂时
while( *pEnd != '\0' )
pEnd++;
//pEnd此时已经指向'\0'了,退一个,指向最后一个字母
pEnd--;
//另外一种方法得到pEnd
//pEnd = pEnd + strlen(input) - 1;
cout << "反转前:" << input << endl;
Reverse( pBegin, pEnd );
cout << "反转后:" << input << endl;
if( (input == NULL