基本上,在這個循環的情況下: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