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

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

#include  
#include  
#include  
using namespace std;  
int main()  
{  
    stack s;  
    queue 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<<"是回文"<

 

你可能感兴趣的:(C,C++)