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

  Ientify and provide an assessment of the risks associated

a new client of your security consulting firm is worried about the potential for data leaks that could expose it to

  Explain why modem block ciphers are designed

Explain why modem block ciphers are designed as substitution ciphers instead of transposition ciphers.

  Compare edi and xml technologies

Explain how electronic data interchange is used to link two companies' business processes together.- Compare EDI and XML technologies.

  Calculate and plot the temperature distribution

A lubricating oil flows through a long 0.6 cm inner-diameter tube at a mean velocity of 6 m/s.

  Discuss tools and techniques for removing malware

Discuss tools and techniques for removing Malware using the text Internet, and/or your job as reference for full credit

  Evaluate the efficiency and accuracy of storage techniques

Evaluate the efficiency, speed, and accuracy of the storage and retrieval techniques that two search engine organizations currently use.

  How the two algorithms differ in their exploration

E28: Mobile Robotics - Fall 2015 - HOMEWORK 8. Keep the default start and goal state. Run A* search (use the Euclidean heuristic). Then, run Dijkstra's algorithm (you should allow diagonal movement) and compare the results. Explain how the two algo..

  Explain the s-access memory organ ration for vector accesses

Explain the S-access memory organ ration, C-access memory organization and OS-access memory organization for vector accesses.

  How internal auditing contributes to effectiveness of act

What is the responsibility by of audit committee of Sarbanes-Oxley of 2002? Explain how internal auditing contributes to the effectiveness of the purpose and goals of the Sarbanes-Oxley Act.

  Determine the temperature drop of water

Hot water is flowing at an average velocity of 4 ft/s through a cast iron pipe (k = 30 Btu/h.ft.°F) whose inner and outer diameters are 1.0 in and 1.2 in.

  Define the chinese remainder theorem and its application

Define the Chinese remainder theorem and its application. Define quadratic congruence and the importance of QRs and QNRs in solving quadratic equations.

  Questionweve been focusing on operational databases often

questionweve been focusing on operational databases often called online transaction processing oltp systems. these oltp

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