Stacks

I was in the process of this program and I'm havin a of problem with my temp stack. Basically, If the gumball i am lookin for is being blocked by other gumballs, im tryin to move all blocking gumballs out of the way—in order; then remove the color gumball that is requested and print its description, then move the blocking gumballs back in their original order... while keeping a count of how many times it has been moved. How should i go about creating this temporary stack to hold the stack in order? should i store the count with the color of the gumball, is that most efficient?

my main:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    Stack s;
    Gumball g;
    char choice;
    bool choice_flag = true;
    bool t;
    bool f;

    do {
        cin >> choice;
        cin >> g.color;
        switch(choice)
        {
            case 'b':
            case 'B':
            cout << "A" << " " << g.color << " gumball has been bought." << endl << endl;
            t = s.isempty();
            s.push();
            f = s.isfull();
            if(f == true)
                cout << "There is no room for another gumball." << endl << endl;
            else
                cout << "The gumball is" << " " << g.color << " and has been stored." << endl << endl;
            break;
            case 'e':
            case 'E':
            cout << "A" << " " << g.color << " gumball has been eaten." << endl << endl;
            t = s.isempty();
            s.pop();
            break;
            case 'q':
            case 'Q':
                choice_flag = false;
                break;
        }
    } while(choice_flag);


my .cpp (pop() and push() )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
void Stack::push()
{
    top++;
    gumballs[top];
    return;
}

// Function to remove and return top item of stack
int Stack::pop()
{
    int x;

    x = gumballs[top];
    top--;
    return x;
}


Any suggestions would be appreciated, thank you
your push operation of stack don't push any item into your define temp stack.
void Stack::push(X x)
{
top++;
gumballs[top] = x;
return;
}

you can define a enum var as a color list.
then gumballs[top] = a color var of enum.
more better you use a color var of enum to as a index of gumballs.
Topic archived. No new replies allowed.