スタックとキューを使用して、特定の単語が回文であるかどうかを確認します。新しいキャラクターをスタックにプッシュできますが、複数のキャラクターをキューにプッシュすることはできません。コードのどこが間違っているのかわかりません。どんな助けでも大歓迎です。以下は、Dev-C++ を使用した C++ のコードです。御時間ありがとうございます!
#include <iostream>
#include <stack>
#include <queue>
#include <string>
using namespace std;
void push_char()
{
string givenword; int sizeword, countchar;
string letter;
stack<string> stackword; string stawo1;
queue<string> queueword; string quewo1;
cout<<"enter the word to test "<<endl;
getline(cin,givenword);
string str (givenword);
sizeword=str.size();
cout<<" the word given "<<givenword<<" size of word= "<<sizeword <<endl;
countchar=0;
bool pali=true;
while ((countchar<sizeword))
{
stackword.push(str.substr(countchar,1));
queueword.push(str.substr(countchar,1));
cout<<" stack letter= "<<stackword.top()<<" queue letter= "<<queueword.front()<<endl;
countchar++;
if(stackword.top()==queueword.front())
cout<<"same letter found !"<<endl;
else
pali=false;
if (pali==false)
cout<<"not a palindrome"<<endl;
else
cout<<"palindrome!"<<endl;
}
}
int main()
{
push_char();
}