使用堆栈实现一下功能:把输入的字符串颠倒过来,如:输入“I am bill”,则输出“bill am I”,用C++语言

来源:百度知道 编辑:UC知道 时间:2024/05/25 19:28:35
要求: 写出C或C++的程序!!!!!!

#include <iostream.h>

/*
* Function: reverse_src_word_by_word
* Discription: Reverse string word by word
*/
inline
char *reverse_str_word_by_word(char *strDes, char *strSrc)
{
char *p1, *p2;
char *pszDest;
int nLen;

if ((NULL == strDes) || (NULL == strSrc))
{
return NULL;
}

/* Search a char from the strSrc */
p1 = strSrc + strlen(strSrc) - 1;
p2 = p1;
pszDest = strDes;

while (p1 != strSrc)
{
if (' ' == *p1)
{
/* Find a word and copy */
nLen = p2 - p1;
memcpy(pszDest, p1 + 1, nLen);
pszDest += nLen;
*pszDest++ = ' ';

p1--;
p2 = p1;
}
else
{
p1--;
}
}

/* The last reverse word */
if (*p1 == ' ')
{<