Stacks help

Pages: 1234
I dont want my teacher to accuse me of cheating or plaigarism

You don't like to be accused? Does that leave the options:
A. Don't cheat
B. Don't get caught
The option A is much easier, considering the technology that the teacher can now use.

What can you learn from the code that you can't use?
What can you learn from the errors that you have made?
Don't answer to us, answer to yourself.
Here is most of the algorithm, taken right from the previously posted code. Try writing your own code to match it
1
2
3
4
5
6
7
8
9
bool isParenthesisBalanced(string exp)
{
    stack<char> s;
    for (int i = 0; i < exp.length(); ++i)
    {
        // if we encounter opening braces, we push them on to the stack
        // if we encounter closing braces, then pop the stack and see if the closing brace matches
    }
}


There are two special cases that you'll need to add:
- What if the stack is empty when you encounter a closing brace? That happens when there is an extra closing brace somewhere.
- What if the stack is not empty when you're done processing the string? That happens when there is an extra opening brace somewhere.
This is what I have now. Can someone help me to get this to ouput. Getting a "Cannot open include "bits/stdc" error message

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
56
57
58
59
60
61
62
#include <iostream>
#include <string>
#include <stack>



using namespace std;


//Function prototype
bool isBalanced(string s);

int main() {

    string str;
    cout << "Enter a parenthesis string: " << endl;
    cin >> str;

    if (isBalanced(str))
        cout << "This is a balanced parenthesis string. " << endl;
    else
        cout << "This is not a balanced parenthesis string. " << endl;

    return 0;
}

bool isBalanced(string str) {
    stack <char> charStack;
    char x;

    for (int k = 0; k < str.length(); k++)
    {
        {
            switch (str[k])
            {
            case '(':
                // THIS IS WEHRE YOU PUT left paren on stack
                charStack.push(str[k]); break;
            case ')':
                //  CHECK TO SEE IF THE right paren has a mate on the stack
                if (charStack.empty())
                    return false;
                else
                    charStack.pop();
                break;
            default:
                // ITHIS IS HOW YOU ignore all other characters
                ;
            }
        }

        if (charStack.empty() || !isBalanced(charStack.top(), str[k]))
            return false;
        else 
            charStack.pop();
    }
    }

    //Check empty stack
    return charStack.empty());

}
Lines 32 & 33. You don't need both blocks. Delete line 33 and the matching '}' at line 50.
Lines 41-45: You aren't actually checking if the character matches what's on the stack.
Line 52: why7 is this calling isBalanced again? Why is it passing two parameters?

Line 55: why do you pop exactly one item? How many items should be on the stack here? None? One? 75? Why?

Coding isn't like writing an essay where you can babble on about random stuff. In programming, you have to be extremely precise. Every statement means something specific and you need to understand and intend every single one.
thank you
thank you

fuck you
Your point ?

The point is that you are a liar and a cheat.
Last edited on
I dont want my teacher to accuse me of cheating or plaigarism

If this thread is any indication you've done a lot to show the accusation has merit.
Getting a "Cannot open include "bits/stdc" error message

<bits/stdc++.h> is a GCC implementation use only header, used as an implementation of a compiled header setup. It is not available with any other compiler, certainly not MSVC.

It is not to be included by the programmer.

Competition sites use it, and do it for specific and IMO wrong reasons.
can someone help me fix this ? i need a queue to check to see if balanced parenthesis
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>
#include <string>
#include <queue>

using namespace std;

class isBalanced {
	string* arr;
	string FrontNode;

	isBalanced() {
		arr = newString[30];
}
	void putInQueue{
	rear = (rear + 1);
	arr[rear] = item;
	count++;
	}
		void takeOutQueue{
		frontNode = arr[front];
		count--;
	}
		void main()
	{
		string firstparens = "";
		string secondparens = "";
		for (int i = 0; i < arr.length(); i++) {
			if (arr[i] == "("))
			firstparens = "("
				if ((firstparens == "(") && (secondparens == ")")
					cout << "hit";
		}
	}
};

Fix what? That code doesn't even compile, so start by looking at your compiler errirs and fixing them.

Also, you would help yourself enormously if you adopted a sensible indentation style. That would help you see at a glance the logic and structure of your code.
You keep posting completely new implementations. You need to learn this stuff. Fix one of the earlier ones.
Because people keep accusing me of hearing. So I started fresh with a new implementation. I’m a true beginner but in this C++ college course. I’m getting errors but don’t know how to fix the errors. I would appreciate some help
cblack618 is a liar and a cheat.
Do not help him.

* this is an automated response
Go away
cblack618 is a liar and a cheat.
Do not help him...

* this is an automated response
If you're getting errors, why aren't you telling us what the errors are? How does it benefit you to withold that information from the people who might be able to help you?
You want me to list each error one by one ???????????????????????????????????????
cblack618 is a liar and a cheat.
Do not help him.

* this is an automated response
I thought the purpose of the "edit and run" function built in on was for someone to see whether the code i posted compiles or what errors popped up ? versuses listing them all invidually
Pages: 1234