Question: 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 Stack interface does not help, as it gives us no way to directly access or remove the object on the bottom of the stack.

Your Task:

Implement the following MyLeakyStack class using array.

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!