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;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education