C++ Programming Activity: Linked List Stack and Brackets Explain the flow of the main code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS int main(int argc, char** argv) {     SLLStack* stack = new SLLStack();     int test;     int length;     string str;     char top;     bool flag = true;     cin >> test;     switch (test) {         case 0:             getline(cin, str);              length = str.length();              for(int i = 0; i < length; i++){                 if(str[i] == '{' || str[i] == '(' || str[i] == '['){                     stack->push(str[i]);                 } else if (str[i] == '}' || str[i] == ')' || str[i] == ']'){                     if(!stack->isEmpty()){                         top = stack->top();                         if(top == '{' && str[i] == '}' || top == '(' && str[i] == ')' || top == '[' && str[i] == ']'){                              stack->pop();                         } else {                             cout << "not accepted";                              flag = false;                             break;                                          }                     } else {                         cout << "not accepted" << endl;                          flag = false;                         break;                     }                 }             }             if(flag == true){                 if(!stack->isEmpty()) {                     cout << "not accepted";                 } else {                     cout << "accepted";                 }             }             break;

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter16: Graphics
Section: Chapter Questions
Problem 14RQ
Question

C++ Programming
Activity: Linked List Stack and Brackets
Explain the flow of the main code not necessarily every line, as long as you explain what the important parts of the code do. The code is already correct, just explain the flow


SEE ATTACHED PHOTO FOR THE PROBLEM INSTRUCTIONS

int main(int argc, char** argv) {
    SLLStack* stack = new SLLStack();
    int test;
    int length;
    string str;
    char top;
    bool flag = true;
    cin >> test;
    switch (test) {
        case 0:
            getline(cin, str);
             length = str.length();
             for(int i = 0; i < length; i++){
                if(str[i] == '{' || str[i] == '(' || str[i] == '['){
                    stack->push(str[i]);
                } else if (str[i] == '}' || str[i] == ')' || str[i] == ']'){
                    if(!stack->isEmpty()){
                        top = stack->top();
                        if(top == '{' && str[i] == '}' || top == '(' && str[i] == ')' || top == '[' && str[i] == ']'){
                             stack->pop();
                        } else {
                            cout << "not accepted"; 
                            flag = false;
                            break;                 
                        }
                    } else {
                        cout << "not accepted" << endl; 
                        flag = false;
                        break;
                    }
                }
            }
            if(flag == true){
                if(!stack->isEmpty()) {
                    cout << "not accepted";
                } else {
                    cout << "accepted";
                }
            }
            break;
Additionally, you are also going to solve the Brackets Problem in
the case O of the main.cpp file where you have to identify
whether a given string that contains brackets is valid or not.
Brackets may be parentheses ( and ), curly brackets { and },
and square brackets [ and ]. Each opening symbol must match
its corresponding closing symbol. For example, a left bracket,
"L" must match a corresponding right bracket, "]," as in the
following expression: [(0]
Take note of the three considerations that will make the string
invalid: a mismatch where the closing bracket did not match
what was in the top of the stack (e.g. "(1)"), an excess opening
where we have completed checking the string where there
should have been more closing bracket/s (e.g. "(0"), and an
excess closing where we found a closing bracket but there's no
opening bracket to match it with (e.g. "0)").
Using the methods of a stack and your SLL implementation,
create a separate program that will print accepted if a given
string is valid exclusively in terms of brace pairing and
otherwise, print not accepted.
Input
For SLLStack Implementation (case 1+): Don't Care
For Braces Implementation (case 0): A string of brackets
Transcribed Image Text:Additionally, you are also going to solve the Brackets Problem in the case O of the main.cpp file where you have to identify whether a given string that contains brackets is valid or not. Brackets may be parentheses ( and ), curly brackets { and }, and square brackets [ and ]. Each opening symbol must match its corresponding closing symbol. For example, a left bracket, "L" must match a corresponding right bracket, "]," as in the following expression: [(0] Take note of the three considerations that will make the string invalid: a mismatch where the closing bracket did not match what was in the top of the stack (e.g. "(1)"), an excess opening where we have completed checking the string where there should have been more closing bracket/s (e.g. "(0"), and an excess closing where we found a closing bracket but there's no opening bracket to match it with (e.g. "0)"). Using the methods of a stack and your SLL implementation, create a separate program that will print accepted if a given string is valid exclusively in terms of brace pairing and otherwise, print not accepted. Input For SLLStack Implementation (case 1+): Don't Care For Braces Implementation (case 0): A string of brackets
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT