Question: -- Instruction -- Given: You are given a Python Class template. In this template, there 3 classes: MyQueue, MyStack. The goal of this lab is
-- Instruction --
Given: You are given a Python Class template. In this template, there 3 classes: MyQueue, MyStack. The goal of this lab is to implement sequential stacks and queues. Task:
- First, create a method called getName() that returns your name. If this does not work, you will receive a mark of zero.
- You are to create Queue and Stack ADTs using a sequential implementation.
- A class called MyQueue is given. You are to implement the methods enqueue(), dequeue(), and the over loaded __len__() method. Enqueue should add an item to the queue. Dequeue should remove an item from the queue. The function __len__() should return the number of items in the queue. All methods MUST be O(1).
- A class called MyStack is given. You are to implement the methods push(), pop(), and the over loaded __len__() method. Push should add an item to the stack. Pop should remove an item from the stack. The function ___len__() should return the number of items in the stack. All methods MUST be O(1). Rule: You MUST use Python's list in your implementation. However you cannot use any built-in list methods such as append, pop, clear, etc. You are also not allow to use any splicing. The only permissible way to manipulate a list is to access it through it's index. Example: array[i] = x
-- Start Up File --
def getName(): return "Last name, first name" class MyQueue: def __init__(self, data=None, maxSize = 100000): # Initialize this queue, and store data if it exists pass
def enqueue(self, data): # Add data to the end of the queue pass
def dequeue(self): # Return the data in the element at the beginning of the queue, or None if the queue is empty pass
def __len__(self): # Return the number of elements in the stack pass
class MyStack: def __init__(self, data=None, maxSize = 100000): # Initialize this stack, and store data if it exists pass def push(self, data): # Add data to the beginning of the stack pass
def pop(self): # Return the data in the element at the beginning of the stack, or None if the stack is empty pass
def __len__(self): # Return the number of elements in the stack pass
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
