Question
{ 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started