Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

{ nbformat: 4, nbformat_minor: 0, metadata: { colab: { name: ATMqueueBooksstack.ipynb, provenance: [] }, kernelspec: { name: python3, display_name: Python 3 }, language_info: { name:

{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "name": "ATMqueueBooksstack.ipynb", "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "metadata": { "id": "hHejWSCi2F4Q" }, "source": [ "class BookandATM: ", " ", " def __init__(self, value): ", " self.value = value ", " self.next = None ", " ", " def getvalue(self): ", " return self.value ", " ", " def setvalue(self,value): ", " self.value = value ", " ", " def setnext(self, next): ", " self.next = next ", " ", " def getnext(self): ", " return self.next ", " ", "class List: ", " ", " def __init__(self): ", " self.first = None ", " ", " def getfirst(self): ", " return self.first ", " def setfirst(self, first:int): ", " self.first = first ", " ", " def traverse(self): #This is O(n) ", " current = self.first ", " while current != None: ", " print(current.getvalue(), end=' ') ", " current = current.getnext() ", " print(\"\") ", " ", " def insert(self, item): #This is O(n) ", " if self.first == None: ", " self.first = item ", " return ", " current = self.first ", " while current != None: ", " if (current.getnext() == None): ", " current.setnext(item) ", " return ", " current = current.getnext() ", "###########################################################33 ", "class Bookstack: ", " def __init__(self): ", " self.first = None ", " ", " def getfirst(self): ", " return self.first ", " def setfirst(self, first:int): ", " self.first = first ", " ", " def traverse(self): ", " current = self.first ", " while current != None: ", " print(current.getvalue(), end=' ') ", " current = current.getnext() ", " print(\"\") ", " ", " def push(self, to_be_inserted): ", " to_be_inserted.setnext(self.first) ", " self.first = to_be_inserted ", " ", " def pop(self): ", " if self.first == None: ", " return None ", " else: ", " top_element = self.first ", " self.first = self.first.getnext() ", " return top_element ", " ", "######################################## ", "class ATMdrivethruQueue: ", " def __init__(self): ", " self.first = None ", " ", " def getfirst(self): ", " return self.first ", " def setfirst(self, first:int): ", " self.first = first ", " ", " def traverse(self): ", " current = self.first ", " while current != None: ", " print(current.getvalue(), end=' ') ", " current = current.getnext() ", " print(\"\") ", " ", " def add(self, to_be_inserted): ", " to_be_inserted.setnext(self.first) ", " self.first = to_be_inserted ", " ", " def remove(self): ", " if self.first == None: ", " return False ", " if self.first.getnext() == None: ", " item = self.first ", " self.first = None ", " return item ", " ", " current = self.first ", " previous = self.first ", " while current != None: ", " if current.getnext() == None: ", " #I need to remove it ", " previous.setnext(None) ", " return current ", " previous = current ", " current = current.getnext() ", " ", " ", " ", "######################################## ", "def main(): ", " stack = Bookstack() ", " stack.push(BookandATM(\"Book1\")) ", " stack.push(BookandATM(\"Book2\")) ", " stack.push(BookandATM(\"Book3\")) ", " print(\"Here is the book stack list!\") ", " stack.traverse() ", " #============== ", " print(\"---------------------\") ", " print(\"Put another book into a shelf\") ", " stack.push(BookandATM(\"Book4\")) ", " stack.traverse() ", " print(\"---------------------\") ", " #============== ", " print(\"Put another book into a same shelf\") ", " stack.push(BookandATM(\"Book5\")) ", " stack.traverse() ", " print(\"---------------------\") ", " ", " ##Let's start popping items off the stack! ", " print(\"Removing a book from a shelf. Last in First Out!\") ", " stack.pop() ", " stack.traverse() ", " print(\"---------------------\") ", " print(\"Removing a book from a shelf. Last in First Out!\") ", " stack.pop() ", " stack.traverse() ", " print(\"---------------------\") ", " ", " ####################################################### ", " print(\" Let's now experiment with a queue object...\") ", " print(\"ATM drive-thru queue\") ", " #Construct a queue object about ATM drive-thru ", " ", " queue = ATMdrivethruQueue() ", " queue.add(BookandATM(\"customer1\")) ", " queue.add(BookandATM(\"customer2\")) ", " queue.add(BookandATM(\"customer3\")) ", " print(\"Here is the queue!\") ", " queue.traverse() ", " print(\"---------------------\") ", " #============== ", " print(\"New custmoer enter the queue...\") ", " queue.add(BookandATM(\"customer4\")) ", " queue.traverse() ", " print(\"---------------------\") ", " #============== ", " print(\"New custmoer enter the queue...\") ", " queue.add(BookandATM(\"customer5\")) ", " queue.traverse() ", " print(\"---------------------\") ", " ", " ##Let's start dequeing items ", " ", " print(\"The service is done for customer1, let him/her go !\") ", " queue.remove() # ", " queue.traverse() ", " print(\"---------------------\") ", " ", " print(\"The service is done for customer2, let him/her go !\") ", " queue.remove() ", " queue.traverse() ", " print(\"=====================\") ", " ", " ", "main()" ], "execution_count": null, "outputs": [] } ]}This is an example of what i need I need a different topic and a good explanation of the cod Please help me it's do today

image text in transcribedimage text in transcribed
1m Use the following instructional materials to complete this discussion: Our In Class Labs + Textbook's sections on queues, stacks and trees. For Module 5 we will direct our attention on the workings (and on the complexity) those algorithms that perform operations on a stack, a queue or a tree. 0 (1) (2.5 points) 0 Refer to the .ipynb files that we have under Module 5. These files illustrate operations on queues, stacks and trees. 0 Think of a problem statement that may be solved using a combination of two or more of the following operations: - stack operations: push(p), pop(), peek(), is_empty() - queue operations: add(p)Ir remove(), peek(), is_empty() - For example: You may use a stack object to more efficiently serve requests in a LIFO fashion. You may use a queue object to more efficiently serve requests in a FIFO fashion. "cells": "cell type": "code", "metadata" : { "id": "hHejWSCi2F4Q" } " source" : [ "class BookandATM: \ ", "\ " def init (self, value) : \ ", self . value = value\ ", self . next = None\ ", In", def getvalue (self) : \ " return self . value\ ", In", def setvalue (self, value) : \ ", self . value = value\ ", In", def setnext (self, next) : \ ", self . next = next \ ", "\ " def getnext (self) : \ ", return self. next\ ", "\ ", "class List: \ ", "\ " def init (self) : \ " self . first = None \ ", In", def getfirst (self) : \ ", return self . first\ ", def setfirst (self, first :int) : \ "

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions