Question: Write a program to read random strings from a user, consisting of any number of ( and ) in any combination, and determine whether

Write a program to read random strings from a user, consisting of any number of  # push item onto stack def push(self,x): # code goes here #pops item from top of stack def pop(self): # code # returns Boolean of whether queue is currently full def isFull(self): # code goes here #clears the queue def # Check if string s has balanced parenthesis def isBalanced(self, s): # code goes here class Queue For implementing interface INode, the expected implementing class should be a doubly-linked node, as in the # more setting statements here userString = None # a loop to ask input via console for new string to check Expected Output: Accurate determination of balanced parentheses in input strings, for both string checking

Write a program to read random strings from a user, consisting of any number of "(" and ")" in any combination, and determine whether they contain balanced parentheses until the user wishes to end the program. A string with balanced parentheses is one where each "(" is paired with a ")". For instance, the string "()((())))" has balanced parentheses, but the strings "(", "", "(0", "))(" and "()(0))(0)" do not have balanced parentheses. Given the data structures from the course material, there are two ways you can implement a technique for checking balanced parentheses. 1. Implement a class that uses a stack to determine if a string has balanced parentheses 2. Implement a class that uses queues to determine if a string has balanced parentheses (Hint: two queues can be used to simulate a stack's behavior). Instead of using arrays for the underlying structures of stacks and queues, use linked list representations that do not use built-in list classes. The program may be implemented either in Python, Java, or C++. The program implemented in either language MUST be well-commented, i.e. use block comments for describing each method in a class and give some lines of comments to explain statements. Programs with very few comments (as in just commenting on one of two methods only) or no comments at all will receive a small penalty. If you implement the program in Python, you must write a Class Queue, a Class Stack, a Class Node, a Class Linked List, and a Class StackParenthesesChecker. class Stack(object): __linked List=... __top= ... # constructor for stack class def_init_(self): # code goes here # push item onto stack def push(self,x): # code goes here #pops item from top of stack def pop(self): # code goes here (should return item from top of stack or None if stack is empty) # returns Boolean of whether stack is currently empty def isEmpty(self): # code goes here # returns Boolean of whether stack is currently full def isFull(self): #code goes here #clears the stack def clear(self): #code goes here # looks at the top item of the stack without removing it def peek(self): # code goes here class Queue (object): __._linkedList=... _front=... _rear = # constructor for Queue class def_init_(self): #code goes her # adds item to front of queue def enqueue(self, x): #code goes here # removes item from rear of queue def dequeue(self): #code goes here (should return item from end of queue or None if queue is empty) # returns Boolean of whether queue is currently empty def isEmpty(self): # code goes here # returns Boolean of whether queue is currently full def isFull(self): #code goes here #clears the queue def clear(self): #code goes here #looks at the item at the end of the queue without removing it def poll(self): # code goes here class Linked List (object): _head=None __tail= None _capacity=0 _size=0 # constructor for LinkedList class def __init__(self): # code goes her # add item x to list at index i def add(self, i, x): #code goes here # remove item at index i from the list def remove(self, i): #code goes here (should return item from list or None if item is not in the list) class Node(object): _data = None ___prev = None _next = None # constructor for Node class def__init_(self): #code goes here class StackParenthesesChecker(object): ___stack = ... # constructor for StackParenthesesChecker class def __init__(self): #code goes here # Check if string s has balanced parenthesis def isBalanced(self, s): # code goes here class QueueParenthesesChecker(object): __queue1 = ... __queue2 =... # constructor for QueueParenthesesChecker class def_init__(self): # code goes here # Check if string s has balanced parenthesis def isBalanced(self, s): # code goes here For implementing interface INode, the expected implementing class should be a doubly-linked node, as in the Python version. INode provides only the getter method for next. The implemented Node class will also require getters and setters for a prev attribute, and you will need to cast in your linked list implementation to access the method. Just as in the Python version, two ParenthesesChecker implementing classes must be implemented. Setters and getters are not written for stacks or queues in the interface due to that information only being in context of the class. So, when setting the data structures in the main method, class casting must be used as well to connect the queues to QueueParenthesesChecker and the stack with StackParenthesesChecker. Create several string examples to check functionality of your program. Please see Testing Phase below. Implementation Phase You must work on the assignment individually. If any external source code or information from a website is applied to your implementation, you MUST acknowledge the source with comments in your code. Testing Phase In Python: main.py file... # add import statements here def main(): checker1 = StackParenthesesChecker() checker2 = QueueParenthesesChecker() stack Stack() queue1= Queue() queue2 Queue() setAttribute(stack, '_Stack_linkedList', LinkedList()) setAttribute(queue1, '_Queue_linkedList', LinkedList()) # more setting statements here userString = None # a loop to ask input via console for new string to check with both checkers While user wants to continue program: userString = get user string via console // add more code here to set up checkers and their data structures If checker1.isBalanced (userString) and checker2.isBalanced (userString)): print("The input string %s has balanced parentheses.", userString) Else: print('The input string %s does not have balanced parentheses.', userString) # get user continuation of program via console If name=__main__': main() Expected Output: Accurate determination of balanced parentheses in input strings, for both string checking techniques. The if-statement where the methods are called for checking balance determines whether checks for both techniques are equivalent.

Step by Step Solution

3.47 Rating (147 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer class Node def initself data selfdata data selfnext None class LinkedLis... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!