栈和队列练习—判断字符串是否 回文

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Fiverya/article/details/88814244

利用栈和队列的特性设计一个算法,用于判断一个字符串是否为回文。

#include<iostream>  
#include<stack>  
#include<queue>  
using namespace std;  
int main()  
{  
    stack<char> s;  
    queue<char> t;  
    char c;  
    int i=0;  
    while((c=getchar())!='\n')  
    {  
        s.push(c);  
        t.push(c);  
        i++;  
    }  
    while(i--)  
    {  
        if(s.top()==t.front())  
            {s.pop();  t.pop(); }  
        else { cout<<"不";break;}  
    }  
    cout<<"是回文"<<endl;   
    return 0;  
} 

猜你喜欢

转载自blog.csdn.net/Fiverya/article/details/88814244