Я решил проблему с bool, но теперь выход не печатает целое слово спереди и назад. только частично. Я опубликовал вывод ниже. Я довольно застрял на этом. Я пробовал множество способов исправить это. Я знаю, что есть какой-то гуру C++, который может пожелать протянуть руку и советы?Как заставить эту очередь работать для палиндрома?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
#include "Queue.h"
void print(string s1, string q1)
{
cout << s1 << " ";
cout << q1 << endl;
}
int main()
{
bool isPalin= true;
string word;
//string temp;
Stack s1;
Queue q1;
void print(string, string);
cout<< " Enter a word you would like to see if it is a palindrome: \n";
getline(cin, word);
cout<< "The word you entered is: "<< word<< endl;
for (int i = 0; i<(word.size()-1); i++)
{
string temp(word, i, 1);
s1.push(temp);
}
for (int i = 0; i<(word.size()-1); i++)
{
string temp(word, i,1);
q1.enqueue(temp);
}
while (!s1.empty())
{
print(s1.top(), q1.front());
if(s1.top() != q1.front())
{
isPalin = false;
s1.pop();
q1.dequeue();
}
cout<< " Lets check if this word is a palindrome" << boolalpha<< isPalin<<endl;
}
Output:
Enter a word you would like to see if it is a palindrome:
hello
The word you entered is: hello
l h
Lets check if this word is a palindromefalse
l e
Lets check if this word is a palindromefalse
e l
Lets check if this word is a palindromefalse
h l
Lets check if this word is a palindromefalse
Queue created.
Какая ошибка возникает у вас? –
Мне нужно было объявить его как bool. забыл сделать это! Теперь он просто не печатает правильно. Любые советы будут оценены! –