Microsoft Word - Program_01.docx
SCSU CSC212‐03 Fall 2019
Programming Assignment 01:
Stacks, Queues, and DEqueues
Due Date: 10‐07‐2019 (in‐class at 6:15pm)
In this programming assignment, you will need to solve the following two problems:
Problem#1:
You have to design a stack that uses two queues for data storage (instead of, for example,
a python list as we’ve seen in class). Specifically, you need to write a class named
‘Stack_2Queues’ that will have the following member methods: push, pop, size, and
is_empty. Follow standard OOP principles of Python as discussed in the class. In addition
to the stack ADT methods mentioned above, also include (i) a method in your class to
convert an object/instance of your class to a string representation, such that that object can
e passed to the print() function for viewing its contents (vertically, the top element should
e at the top), and (ii) a method that allows an instance of this class to be passed to the len()
function and shows its size. Save this class in a file named ‘MyStack.py’. For the two queue
instances, use the queue class ‘Queue_PlistLR’ made available to you with this assignment.
You also need to write a python program (and save it as MyStack_test.py) to demonstrate
that your implementation is co
ect by comparing it with the results of usual stack
operations performed on a reference stack (use the class ‘Stack_PlistLR’ as the reference
stack).
Hints: For the test program, perform the same operations on the two implementations of a
stack and show their contents after each operation. Use a tabular form to display this
information.
Problem#2:
Design a queue that uses two stacks for storing data (instead of, for example, a python list
as we’ve seen in class). Specifically, you need to write a class named ‘Queue_2Stacks’ that
will have the following member methods: enqueue, dequeue, size, and is_empty. In
addition to the stack ADT methods mentioned above, also include (i) a method in your
class to convert an object of your class to a string representation, such that the object can
e passed to the print() function for viewing its contents (horizontally, the front element
should be at the leftmost position), and (ii) a method that allows an instance of this class to
e passed to the len() function and shows its size. Save this class in a file named
‘MyQueue.py’. For the two stacks, use the stack class ‘Stack_PlistLR’ made available to
you with this assignment. You also need to write a python program (save it as
MyQueue_test.py) to demonstrate that your implementation is co
ect by comparing it with
the results of operations performed on a reference queue (use the class ‘Queue_PlistLR’ as
the reference queue).
Hints: Perform the same operations on the two implementations of a queue and show their
contents after each operation. Use a tabular form to display this information.
Additional instructions:
You CANNOT modify either Stack_PlistLR or Queue_PlistLR. Assume as if they are
made available to you by a third party, and you are a python developer who has been tasked
to implement a Stack and a Queue class using those, without modifying the supplied classes
as other people might be using them in their programs/li
ary development, too.
Submission/Demonstration Instructions:
This is an individual assignment that is due in‐class on the due date. Once you have completed
implementing the program, the instructor should be demonstrated of its functionality in order for you to
eceive credits for it. Failing to demonstrate will result in a zero credit.