Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Web browsers commonly allow you to navigate through a history of web pages that have previously been visited. The mechanism is somewhat like a stack,

Web browsers commonly allow you to navigate through a "history" of web pages that have previously been visited. The mechanism is somewhat like a stack, in that the most recently visited pages are at the top of the history and revisited when the "back" button is pressed.

However, the history does not necessarily have unbounded capacity. In reality, there may exist a fixed limit on the size of the history. The issue arises as to what should happen when the capacity is exhausted and a new item is pushed onto the stack. One possibility is to throw an exception. But this is not how a Web browser behaves. If it only has room to save 50 pages in its history and yet you visit more pages, it will make room in the history for a new page by throwing away the page that is on the very bottom of the history (i.e., the least recently visited page). The formal Stackinterface does not help, as it gives us no way to directly access or remove the object on the bottom of the stack.

Your Task:

1. Implement the following MyLeakyStack class

Using Array

Using Singly Linked List

import net.datastructures.*;

public class MyLeakyStack implements Stack {

@Override public int size() { // TODO Auto-generated method stub return 0; }

@Override public boolean isEmpty() { // TODO Auto-generated method stub return false; }

@Override public void push(E e) { // TODO Auto-generated method stub }

@Override public E top() { // TODO Auto-generated method stub return null; }

@Override public E pop() { // TODO Auto-generated method stub return null; }

}

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

Step: 3

blur-text-image

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

Secrets Of Analytical Leaders Insights From Information Insiders

Authors: Wayne Eckerson

1st Edition

1935504347, 9781935504344

More Books

Students also viewed these Databases questions

Question

What's your favorite fast food chain?

Answered: 1 week ago

Question

What is chemistry

Answered: 1 week ago