please help

closed account (4y64izwU)
.....................................
Last edited on
1
2
3
4
queue<int> pid;
if (input == 'A'){
    pid.push(0);
    ....
Last edited on
closed account (4y64izwU)
..........................................................................
Last edited on
closed account (4y64izwU)
.....................................................................
Last edited on
closed account (4y64izwU)
.........................................................................
Last edited on
Look at the if-statement in my code and look at yours then look at mine and back to yours, what do you see? You see a single `=` sign in yours and notice the `==` in mine. Why does yours not look like mine? I don't know. Now back to yours, change it to look like mine and run your code, what happens now?
closed account (4y64izwU)
........................................................................
Last edited on
Paste your new program here and we will see what the problem is
closed account (4y64izwU)
...........................................................................................................
Last edited on
closed account (4y64izwU)
...............................................................................
Last edited on
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
36
37
38
#include <iostream>

int main ()
{
    int qfront = 0 ;
    int qback = 0 ;

    char c ;
    while( std::cin >> c )
    {
        switch(c)
        {
            case 'A':
            case 'a':
                std::cout << "A process with PID " << ++qback << " has arrived!\n" ;
                break ;

            case 'T':
            case 't':
                if( qfront < qback ) std::cout << "A process with PID " << ++qfront << " has died!\n" ;
                break ;

            case '?':
                if( qfront == qback ) std::cout << "no processes are alive.\n" ;
                else if( qfront == (qback-1) ) std::cout << "processes with PID " << qback << " is alive.\n" ;
                else std::cout << "processes with PIDs " << qfront+1 << " to "  << qback << " are alive.\n" ;
                break ;

            case 'Q':
            case 'q':
                return 0 ;

            default:
                std::cout << "invalid input.\n" ;

        }
    }
}
closed account (4y64izwU)
..........................................................................................
Last edited on
This means that you need a stack rather than a queue. A queue will kill the processes in the order they arrived, and a stack will do it in reverse. Also have you tried what JLBorges suggested?
closed account (4y64izwU)
.............................................................................................
Last edited on
Topic archived. No new replies allowed.