Queue help

Pages: 12345
Apr 18, 2020 at 9:42pm
F
Apr 18, 2020 at 9:46pm
At this point, anyone who helps this proven liar and cheat should have their account cancelled.
Apr 18, 2020 at 9:52pm
at this point, you should shut up
Apr 18, 2020 at 9:54pm
At this point, anyone who helps this proven liar and cheat should have their account cancelled.
* this is an automated response
Apr 18, 2020 at 10:35pm
Can someone help me with this queue ?
Apr 18, 2020 at 10:36pm
At this point, anyone who helps this proven liar and cheat should have their account cancelled.
* this is an automated response
Apr 18, 2020 at 10:54pm
cblack618, your code here
http://www.cplusplus.com/forum/beginner/269654/3/#msg1161136
is nearly working.

You just have a few extra closing curly parentheses and an extra semicolon.

I think, if you try to thoroughly indent it, row by row, you should be able to spot them by yourself. I might be wrong, but I don’t see other (big) errors.
It’s not perfect, but it should work.
Apr 18, 2020 at 11:03pm
Hi Enoizat

I made a few changes to the version to pointed me to. I am not good with proper indentation. I just want to make sure this is a queue though ? i already have a stack version done
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <string>
#include <stack>
#include <queue>

using namespace std;

bool isBalanced(string s);

int main()
{

    cout << "This program checks a string to see if its parentheses are properly \n";
    cout << "balanced.";


    string str;
    cout << "\nType in a string with some parenthesis:\n";
    getline(cin, str);


    if (isBalanced(str))
        cout << "The string has balanced parentheses.";
    else
        cout << "The string does not have balanced parentheses.";
    return 0;
}

bool isBalanced(string str)
{
    queue<char> charQueue;
    for (unsigned int k = 0; k < str.length(); k++)
    {
        switch (str[k])
        {
        case '(':
            // Put left paren on stack
            charQueue.push(str[k]); break;
        case ')':

            if (charQueue.empty())
                return false;
            else
                charQueue.pop();
            break;
        default:

            ;
        }
    }
    if (charQueue.empty())
        return true;
    else
        return false;
}
Apr 18, 2020 at 11:29pm
The algorithm is literally identical to the stack version. All you have to do is start with the stack version and change the word "stack" to "queue". Done.

Actually you don't need a stack or queue at all. But that's the assignment.
Last edited on Apr 18, 2020 at 11:29pm
Apr 18, 2020 at 11:45pm
Hi Mbozzi,

I thought i did what you recommended above. I changed stack to queue ? Line 31 is queue
Apr 19, 2020 at 12:27am
I just wanted to point out the similarity between the two versions of the program.

(I didn't bother to read the whole thread, so if you posted the stack version I missed it.)
Apr 19, 2020 at 12:28am
so is my queue version correct ?
Apr 19, 2020 at 1:00am
IDK why don't you test it?
Apr 19, 2020 at 1:19am
It compiles. But want to make sure that it is compiling as a queue rather than stack. I can’t tell the difference
Apr 19, 2020 at 2:52am
It doesn't matter what or how the program compiles. It matters what the source code says. After all, the assignment requires that you deliver source code, and not a compiled program.

Anyway, every programmer works under the assumption that the compiler properly follows the instructions in the source code. Your program tells the compiler to use a queue (on line 31). Therefore, the compiled program uses a queue.

Just because a program compiles doesn't mean it is correct. Test it. Run the program repeatedly, and try to type in an input that makes the program produce the wrong answer.
Apr 19, 2020 at 6:02am
> It compiles. But want to make sure that it is compiling as a queue rather than stack. I can’t tell the difference
You're an easy mark then at a poker game if you can't tell the difference between the word "stack" and the word "queue".

The sky is pink, and you have neither the nouse nor skill to even tell whether I'm telling the truth or not.
Apr 19, 2020 at 1:52pm
Line 44 in your latest version isn't quite correct (where you call charQueue.pop()). Compare this to your working stack version and you should see what's wrong.
Apr 19, 2020 at 2:05pm
It's the same in my working stack version as well
Apr 19, 2020 at 2:06pm
Line 44 in my stack version is

 
 charStack.pop();
Apr 19, 2020 at 2:07pm
so i don't see what's wrong cause it's look the same
Pages: 12345