Question: Complete in Python with comments, thank you. Recall that stacks and queues are abstract data types ( ADTs ) . They support certain basic operations,

Complete in Python with comments, thank you.
Recall that stacks and queues are abstract data types (ADTs). They support certain basic
operations, but these operations can be implemented in different ways. In class, we used a linked
list to build a stack and a queue. In this problem, you'll do the same thing using Python's
built-in list instead of a linked list.
In a file named custom_adts.py, do the following:
(a)(5 points) Write a Stack class that implements a stack ADT using a Python list to store
the stack elements. Use index 0 of the list as the "bottom" of the stack. Your class needs
the following components:
A constructor that initializes the list
A method that returns a string containing the elements in the stack
A size method that returns the number of elements in the stack
A push method that adds a new element to the top of stack
A pop method that removes and returns the element at the top of the stack. If the
stack is empty, this method returns None.
A peek method that returns (without removing) the element at the top of the stack.
If the stack is empty, this method returns None.
(b)(5 points) Write a Queue class that implements a queue ADT using a Python list to store
the queue elements. Use index 0 of the list as the "back" of the queue. Your class needs
the following components:
A constructor that initializes the list
A _str_method that returns a string containing the elements in the queue
A size method that returns the number of elements in the queue
An enqueue method that adds a new element to the back of the queue
A dequeue method that removes and returns the element at the front of the queue. If
the queue is empty, this method returns None.
A peek method that returns (without removing) the element at the front of the queue.
If the queue is empty, this method returns None.
 Complete in Python with comments, thank you. Recall that stacks and

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!