我解决了我的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.
答案 0 :(得分:0)
您似乎忘记在使用之前在某处声明const
。
答案 1 :(得分:0)
这显然是我的循环和我的时间。我试图想到逻辑。堆栈是FIFO,队列是LIFO。但它开始让我困惑我将如何解决这个问题。也许我应该把一个for循环带走,然后将它推入,排队然后出列?
downloadImages(arrayOfAdFileInfo) { downloaded in
// initiate whatever you want when the downloads are done
print("All Done! \(downloaded) downloaded successfully.")
}
// but don't do anything contingent upon the downloading of the images here