HELP PLEASE!!!

Hi.I have to write a c++ programm with a stack struckture.The task is to count if the number of such "(" brackets is equal to ")" these ones.If for example we have (((( )))),then we start from begin and end.If a bracket is "(" we add it to a stos,and if ")" we should remove previous one it seems to me.So in the end stack has to be empty.I'm not good at writing a programm so please help me.And it is also necessary to define the algorythm's time complexity.thanx a lot
See the code

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
#include <iostream>

using namespace std;

int main() {
    char str[80]; //We will use it to store the brackets
    int curr=0; //This will contain current bracket level
    cin>>str;
    for(int i=0; str[i]!='\0' ;i++) // loop till array ends
    {
        if(str[i] == '(' ) curr++; //increase the level
        else if(str[i]==')') curr--; //decrease the level
        if(curr<0){
            break;  // the no of closing brackets are more than opening ones, no need to move on
        } 
    }
    if(curr==0)
    {
        cout<<"Stack Empty";   //Opening and closing brackets are equal in no
    }
    else
    {
        cout<<"Stack not Empty"; 
    }
	return 0;
}
Last edited on
thanx
Please don't provide code to someone who has not offered up any of their own. This is almost definitely a homework project, so creating a culture where people can come and ask for others to do their homework is not something you want to be promoting. If the person isn't good at writing programs, then what good will it do for them to be hand fed the code? They'll never improve unless they put forth at least a little effort and see where they're going wrong. Please ask for at least a rough draft of what they've come up with.

If all it took to learn to program was looking at other people's code we'd all be perfect by now. O_o
Topic archived. No new replies allowed.