Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In class Two.py provided below # This file shall be used to work through inclass assignment two. # For this assignment we will utilize a

image text in transcribed

In class Two.py provided below

# This file shall be used to work through inclass assignment two. # For this assignment we will utilize a stack object and implement three operations # Operation One: Given two stacks, determine if the stacks are identical (same items in same order) # This operation MUST be performed without permanent modification to the original stack. # Operation Two: Given two input stacks, determine if the stacks contain the same set of items, without respect to order # This operation MUST be performed without permanent modification to the original stack. # Operation Three: Using two stacks, simulate the performance of a queue. You must create the enqueue and dequeue functions

# This class contains implementation of an array stack. class Stack(): # Declares an initially empty stack def __init__(self): self.size = 0 self.stack = [] # Pushes an item to the top of the stack def push(self, item): self.stack.append(item) self.size += 1 # Removes the top item from the stack def pop(self): if (self.size

# This function will check to see if two stacks contain the same content (not necessarily same order) # It will not permanently modify either stack. def func_two(stack1, stack2): print("This is a function")

# This class will utilize two stacks to represent a queue class StackQueue: def __init__(self): self.stack1 = Stack() self.stack2 = Stack() self.size = 0 # You may wish to declare other variables def enqueue(self, data): print("Place the enqueue method here")

def dequeue(self): print("Place the dequeue method here")

def __str__(self): return "The contents of the StackQueue are: Stack1: %s Stack2: %s" % (self.stack1, self.stack2) def main(): print("This file will execute the methods of inclass two.") # First to create the stacks that will test functions one and two. sStack1 = Stack() sStack2 = Stack() sStack3 = Stack() sStack4 = Stack() lStack1 = Stack() lStack2 = Stack() lStack3 = Stack() lStack4 = Stack() for i in range(5): sStack1.push(i) sStack2.push(i) for i in range(4,-1,-1): sStack3.push(i) sStack4.push(1) sStack4.push(3) sStack4.push(5) # print(sStack1) # print(sStack2) # print(sStack3) # print(sStack4) for i in range(50): lStack1.push(i) lStack2.push(i) for i in range(49,-1,-1): lStack3.push(i) for i in range(0,50,2): lStack4.push(i)

# print(lStack1) # print(lStack2) # print(lStack3) # print(lStack4) print("First we will test whether or not the stacks are identical.") print("Stacks 1 and 2 for small and large are identical. Stacks 1, 2, and 3 all contain the same datapoints. Stack 4 is missing datapoints compared to stacks 1, 2, and 3.") # print("The result of calling func_one on sStack1 and sStack2 is: %s" % func_one(sStack1, sStack2)) # print("The result of calling func_one on sStack1 and sStack3 is: %s" % func_one(sStack1, sStack3)) # print("The result of calling func_one on sStack1 and sStack4 is: %s" % func_one(sStack1, sStack4)) # print("The result of calling func_one on sStack2 and sStack1 is: %s" % func_one(sStack2, sStack1)) # print("The result of calling func_one on sStack2 and sStack3 is: %s" % func_one(sStack2, sStack3)) # print("The result of calling func_one on sStack2 and sStack4 is: %s" % func_one(sStack2, sStack4)) # print("The result of calling func_one on sStack3 and sStack4 is: %s" % func_one(sStack3, sStack4)) # print("The result of calling func_one on lStack1 and lStack2 is: %s" % func_one(lStack1, lStack2)) # print("The result of calling func_one on lStack1 and lStack3 is: %s" % func_one(lStack1, lStack3)) # print("The result of calling func_one on lStack1 and lStack4 is: %s" % func_one(lStack1, lStack4)) # print("The result of calling func_one on lStack2 and lStack1 is: %s" % func_one(lStack2, lStack1)) # print("The result of calling func_one on lStack2 and lStack3 is: %s" % func_one(lStack2, lStack3)) # print("The result of calling func_one on lStack2 and lStack4 is: %s" % func_one(lStack2, lStack4)) # print("The result of calling func_one on lStack3 and lStack4 is: %s" % func_one(lStack3, lStack4))

# print(" Now for function 2") # print("The result of calling func_two on sStack1 and sStack2 is: %s" % func_two(sStack1, sStack2)) # print("The result of calling func_two on sStack1 and sStack3 is: %s" % func_two(sStack1, sStack3)) # print("The result of calling func_two on sStack1 and sStack4 is: %s" % func_two(sStack1, sStack4)) # print("The result of calling func_two on sStack2 and sStack1 is: %s" % func_two(sStack2, sStack1)) # print("The result of calling func_two on sStack2 and sStack3 is: %s" % func_two(sStack2, sStack3)) # print("The result of calling func_two on sStack2 and sStack4 is: %s" % func_two(sStack2, sStack4)) # print("The result of calling func_two on sStack3 and sStack4 is: %s" % func_two(sStack3, sStack4)) # print("The result of calling func_two on lStack1 and lStack2 is: %s" % func_two(lStack1, lStack2)) # print("The result of calling func_two on lStack1 and lStack3 is: %s" % func_two(lStack1, lStack3)) # print("The result of calling func_two on lStack1 and lStack4 is: %s" % func_two(lStack1, lStack4)) # print("The result of calling func_two on lStack2 and lStack1 is: %s" % func_two(lStack2, lStack1)) # print("The result of calling func_two on lStack2 and lStack3 is: %s" % func_two(lStack2, lStack3)) # print("The result of calling func_two on lStack2 and lStack4 is: %s" % func_two(lStack2, lStack4)) # print("The result of calling func_two on lStack3 and lStack4 is: %s" % func_two(lStack3, lStack4)) # print(" Now for the StackQueue") # my_queue = StackQueue() # my_queue.enqueue(1) # my_queue.enqueue(2) # my_queue.enqueue(3) # my_queue.enqueue(4) # my_queue.enqueue(5) # print(my_queue) # my_queue.dequeue() # my_queue.dequeue() # print(my_queue) # my_queue.enqueue(6) # print(my_queue) # my_queue.enqueue(7) # my_queue.dequeue() # print(my_queue)

main()

Using the base code provided in: inclass two.py implement the following three functions (the same instructions are presented in the .py file) 1) A function to determine if two input stacks are identical (same items in same order). The function must not permanently modify the stack, nor can you use direct access to the array containing the data. You may NOT say stack1.stack or stack2.stack and directly access the array. Your solution must utilize the pop method of the stack to interact with any datapoint within them. (You may utilize structures other than a stack inside the solution) 2) A function to determine if two input stacks contain the same elements. The function must not permanently modify the stack, nor can you use direct access to the array containing the data. You may NOT say stack1.stack or stack2.stack and directly access the array. Your solution must utilize the pop method of the stack to interact with any datapoint within them. (You may utilize structures other than a stack inside the solution) 3) A class definition that supports the enqueue and dequeue functions. However instead of an array (or a linked list), your solution will implement a queue using two stacks to store the data points. You MAY define additional datapoints inside the structure. Test your methods and implementation with the main method provided. For functions 1 and 2, eight arrays have been created, four small size 5 or less) and 4 large size 25-50). For question 3, a runthrough of enqueue and dequeue operations is provided

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Michael V. Mannino

4th Edition

0615231047, 978-0615231044

More Books

Students also viewed these Databases questions

Question

What is the purpose of the Salary Structure Table?

Answered: 1 week ago

Question

What is the scope and use of a Job Family Table?

Answered: 1 week ago