基本上,在这个循环的情况下:e/E ..我的目标是从原堆栈中弹出一个项目,将其存储在临时的gumball中,然后查看颜色那个暂时的口香糖球场。如果这是我想要的,那么我有一场比赛,它的计数器会增加。如果没有,将gumball推到临时堆栈上。然后重复这个过程,直到我找到我想要的或原始堆栈为空。此外,当每个口香糖被吃掉时,要打印它被移动了多少次,因为它阻塞了其他口香糖。当我说吃,它说没有找到,我不明白为什么。有什么建议么??搜索堆栈的值和存储在临时堆栈
我主要看起来像这样(我有问题环路的情况下,E):
#include <iostream>
#include "Stack.h"
#include "Gumball.h"
using namespace std;
int main()
{
Stack s, gumballStack;
Gumball g, temp;
char choice;
bool choice_flag = true;
do {
cin >> choice;
cin >> g.color;
switch(choice)
{
case 'b':
case 'B':
cout << "A" << " " << g.color << " gumball has been bought." << endl << endl;
g.counter = 0;
s.isempty();
s.push(g);
if(!s.isfull())
cout << "The gumball is" << " " << g.color << " and has been stored." << endl << endl;
else
cout << "There is no room for another gumball." << endl << endl;
break;
case 'e':
case 'E':
//s.pop();
s.pop() = temp;
while(!s.isempty() && temp.color != g.color)
{
s.pop().counter++;
gumballStack.push(temp);
s.pop();
cout << " " << g.counter << endl;
}
if(!s.isempty())
{
//cout << " " << g.counter++ << endl;
s.pop();
cout << "A gumball has been eaten." << endl << endl;
// cout << "A" << " " << g.color << " was not found." << endl << endl;
}
else
{
cout << "A" << " " << g.color << " was not found." << endl << endl;
}
while(!gumballStack.isempty())
{
gumballStack.pop();
s.push(gumballStack.pop());
gumballStack.pop();
}
break;
case 'q':
case 'Q':
choice_flag = false;
break;
}
} while(choice_flag);
return 0;
}
你是否在吃它的口香糖,当它匹配你想要的颜色? – jwfriese