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;
Expert Solution
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
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
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