What method would implement that

Assignment Help Computer Engineering
Reference no: EM132112788

PYTHON:

The introduction of Section 6.1 notes that stacks are often used to provide "undo" support in applications like a Web browser or text editor.

While support for undo can be implemented with an unbounded stack, many applications provide onlylimited support for such an undo history, with a fixed-capacity stack.

When push is invoked with the stack at full capacity, rather than throwing an exception, a more typical semantic is to accept the pushed element at the top while "leaking" the oldest element from the bottom of the stack to make room.

Give an implementation of such a LeakyStack abstraction, using a circular array.

Important:

For instance variables you may use a python list, and integers. Nothing else. Nothing. No credit if you violate this rule.

All operations except __str__ should run in constant time (assuming append on lists takes constant time).

I did this :

class LeakyStack:
def __init__(self,maxsize):
self.data = []
self.maxsize=maxsize
self.len = 0

def push(self,x):
if self.len == self.maxsize:
del self.data[0]
self.data.append(x)
else:
self.data.append(x)
self.len += 1

def pop(self):
self.len -= 1
self.data.pop()

def __len__(self):
return self.len

def is_empty(self):
return len(self.data)==0

def __str__(self):
return ' '.join(str(self.data[i]) for i in range (len(self.data)))

But with my method, I can't see where a circular array fits. What method would implement that?

Slicing is not constant runtime so based on the 'important' note I can't use that.

Reference no: EM132112788

Questions Cloud

How to process all entries in the dictionary : How to process all entries in the dictionary if you decide to use something other than the key to search it.
Create two instances of the class employee : Create two instances of the class employee with the following information Alice, worked for 40 hours and is paid $20 per hour Bob.
Write a python program for grocery list manager : Write a python program for grocery list manager and note taking system that has note taking mode and grocery listing mode.
Analyse main aspects of the rm decision-making : Analyse main aspects of the RM decision-making framework the revenue managers of your property considered when implementing strategic and tactical revenue
What method would implement that : But with my method, I can't see where a circular array fits. What method would implement that?
Explain returns to scale : Discuss the economic concept of the long-run average cost curve and how it can be used to explain returns to scale, taking into account the factors that result
Create a python program which will grade a certain portion : Create a Python program which will grade a certain portion of the final. The final has 25 questions where the answer is either, A,B,C or D.
Discuss how the production possibility frontier : Discuss how the production possibility frontier (PPF) can be used to illustrate economic growth include in your answer the main factors that contribute.
Write a test program that creates an account object : Write a test program that creates an Account object with an account ID of 1122, a balance of $20,000, and an annual interest rate of 4.5%.

Reviews

Write a Review

Computer Engineering Questions & Answers

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd