Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The Program Specification Given a symbol string to check parse one character at a time. If the character is an opening delimiter ( e .
The Program Specification
Given a symbol string to check parse one character at a time. If the character is an opening delimiter eg or then it is pushed onto the stack. When a closing delimiter is encountered eg or the stack is popped.
Implement a stack by using Linked lists. A push operation is implemented by inserting a symbol node at the beginning of the list. A pop operating is implementing by deleting a symbol node from the beginning of the list aka the header or top node
Node Class
class Node will contain a constructor, set methods data field and next field get methods and a helper method to determine if the node points to another node.
constructor: init data and next attributes
setters: validate parameters before changing state of private attribute; returns a boolean value if valid parameter
getters: return attributes
helper methods: validate parameter data; checks if a node points to another node
Stack Class
class Stack will contain a constructor, push, pop, peek, isempty, createstack and deletestack methods.
constructor: init head attribute; if data parameter push data onto stack
push: push a node on top of the stack
pop: remove the top node on the stack
peek: if top node exists get data
isempty : checks if empty stack
createstack: class method to create a Stack
deletestack: release all the nodes in the stack.
Test Driver
Instantiates a Stack object.
Obtains user input.
Validates symbol matching.
Algorithm
a Create a stack
b While the end of input is not reached
If the character read is not a symbol to be balanced, ignore it
If the character is an opening symbol push it onto the stack.
If the character is a closing symbol and the stack is empty report an error. Otherwise pop the stack.
If the symbol popped is not the corresponding opening symbol, report an error.
Testing Specification
Provide at least the checks of balanced symbols:
test case
test case
test case
Provide a demonstration that your applications manages
non symbol characters
detects attempting to pop from an empty stack
detects an incorrect pairing symbol popped from the stack
Algorithm Analysis and Performance Evaluation
Give the time and space complexity of your solution.
Example Snippet Test Demonstration
Output
Output
#
What to Turn In
Hand in py files. No zip files.
Hand in node class: Use this title format for your py file : yournamenode.py Note: Use YOUR name
Hand in stack class: Use this title format for your py file : yournamestack.py Note: Use YOUR name
Hand in a test driver file. Name the output file yournameapy Again use YOUR name
Submitting multiple files to an assignment
You will hand in files: your class source files which will contain the Node and Stack classes and the demo test driver file which will additionally contain the commented out run of the output at your console
Your lab assignment requires uploading more than one file; you should upload these files as one submission. In this assignment you need to upload a py file that contains your Node class, a py file that contains your Stack class, and a py file that contains your class test driver all part of one assignment submission. To add these files, the Add Another File button is clicked to upload the two files one by one. Check to make sure that all files get uploaded okay. When finished click Submit Assignment.
Submission Resources
For more information on how to submit your assignment, please visit:
How do I submit an online assignment? Canvas Student Guide
Assignments Overview Canvas Video Guide
Assignments Submissions Canvas Video Guide
Questions?
Feel free to ask in the forum!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started