diff_months: 11

STACK abstract data type :Class Implementation Assignment

Download Solution Now
Added on: 2023-07-06 04:29:35
Order Code: 492055
Question Task Id: 0

Assume the following class implements the STACK abstract data type (ADT) using the array ADT.

 

class aStack(iArray):

def __init__(self, capacity = 5):

self._items = iArray(capacity) self._top = -1 self._size = 0 def push(self, newItem):

self._top += 1 self._size += 1 self._items[self._top] = newItem def pop(self):

oldItem = self._items[self._top] self._items[self._top] = None self._top -= 1 self._size -= 1 return oldItem def peek(self):

return self._items[self._top] def __len__(self):

return self._size def __str__(self): result = ' ' for i in range(len(self)):

result += str(self._items[i]) + ' ' return result

 

Question 3.a Emulate the stack behaviour using the Python list data structure rather than the Array ADT, then list the pros and cons of this approach.

 

 

Question 3.b : Redefine the Stack class methods to push and pop two items rather than one item at a time.

For example, if the stack includes numbers from one to ten: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], then invoking the pop() method twice will remove the last four elements and modify the stack elements to be: [1, 2, 3, 4, 5, 6]

  • Uploaded By : Katthy Wills
  • Posted on : July 06th, 2023
  • Downloads : 0
  • Views : 202

Download Solution Now

Can't find what you're looking for?

Whatsapp Tap to ChatGet instant assistance

Choose a Plan

Premium

80 USD
  • All in Gold, plus:
  • 30-minute live one-to-one session with an expert
    • Understanding Marking Rubric
    • Understanding task requirements
    • Structuring & Formatting
    • Referencing & Citing
Most
Popular

Gold

30 50 USD
  • Get the Full Used Solution
    (Solution is already submitted and 100% plagiarised.
    Can only be used for reference purposes)
Save 33%

Silver

20 USD
  • Journals
  • Peer-Reviewed Articles
  • Books
  • Various other Data Sources – ProQuest, Informit, Scopus, Academic Search Complete, EBSCO, Exerpta Medica Database, and more