您的位置:首页 > 编程语言 > Go语言

堆栈选择性翻转字符串:String:Reverse a string using Stack:the pointer is a very good tool actually

2009-11-29 04:29 609 查看
// TestString.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "iostream"
#include "string"
#include "stack"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
char *LongS="you are My love";
char *Find="My";
stack<char> MyStack;
char *phead=LongS;
char *rear=phead;
char *p=Find;
while(*phead!='/0')
{
while(*phead==*p)
{
phead++;
p++;

}
if(*p=='/0')
{
for(char *temp=phead-1;temp>=rear;temp--)
MyStack.push(*temp);
rear=phead;
p=Find;
}
else
{
MyStack.push(*rear++);
phead=rear;
p=Find;

}
}
while(!MyStack.empty())
{
cout<<MyStack.top();
MyStack.pop();
}
cin.get();
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐