Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USING PYTHON3: Solve def pop(self) for the Stack. class Node(object): A node is a simple container with two pieces of information data: the contained

USING PYTHON3: Solve def pop(self) for the Stack. class Node(object): """  A node is a simple container with two pieces of information  data: the contained information  next: a reference to another node  We can create node-chains of any size.  """  def __init__(self, data, next=None): """  Create a new node for the given data.  Pre-conditions:  data: Any data value to be stored in the node  next: Another node (or None, by default)  """  self._data = data self._next = next class Stack(object): def __init__(self): """  Purpose  creates an empty queue  """  self.__size = 0 # how many elements in the queue  self.__first = None # the node chain starts here  self.__last = None # the node chain ends here   def is_empty(self): """  Purpose  checks if the given queue has no data in it  Pre-conditions:  queue is a queue created by create()  Return:  True if the queue has no data, or false otherwise  """  return self.__size == 0 def size(self): """  Purpose  returns the number of data values in the given queue  Pre-conditions:  queue: a queue created by create()  Return:  The number of data values in the queue  """  return self.__size def push(self, value): """  Purpose  adds the given data value to the given queue  Pre-conditions:  queue: a queue created by create()  value: data to be added  Post-condition:  the value is added to the queue  Return:  (none)  """  n = Node.Node(value) if self.is_empty(): self.__first = n self.__last = n else: n = self.__first n._next = self.__first self.__size += 1 def pop(self): """  Purpose  removes and returns a data value from the given queue  Post-condition:  the first value is removed from the queue  Return:  the first value in the queue, or None  """   TO BE COMPLETE return None  

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

More Books

Students also viewed these Databases questions