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;
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;
Chapter16: Graphics
Section: Chapter Questions
Problem 14RQ
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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2cb11186-80ff-4474-bc75-6eff69002743%2Fee11cfe0-08ad-4125-8d0a-f9991ea90591%2Fangfl4_processed.png&w=3840&q=75)
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
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781305480537/9781305480537_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![EBK JAVA PROGRAMMING](https://www.bartleby.com/isbn_cover_images/9781337671385/9781337671385_smallCoverImage.jpg)
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
![C++ Programming: From Problem Analysis to Program…](https://www.bartleby.com/isbn_cover_images/9781337102087/9781337102087_smallCoverImage.gif)
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
![Microsoft Visual C#](https://www.bartleby.com/isbn_cover_images/9781337102100/9781337102100_smallCoverImage.gif)
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
![C++ for Engineers and Scientists](https://www.bartleby.com/isbn_cover_images/9781133187844/9781133187844_smallCoverImage.gif)
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage