Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class named Intstack that implement the following interface called ILifo: public interface ILifo{ public int getLength ( ); public boolean isEmpty ( );

Design a class named Intstack that implement the following interface called ILifo:
public interface ILifo{
public int getLength ( );
public boolean isEmpty ( );
public void push(int num);
public int pop( );
public int getCapacity( );
public int setCapacity (int newCapacity);
}
image text in transcribed
image text in transcribed
image text in transcribed
Homework 12 ILifo Interface Objectives: .Practice interface implementation. ign a class named IntStack that implement the following interface called Ilifo: public interface ILifo public int getLength) public boolean isEmpty) public void push (int num) public int pop ( public int getcapacity) public int setcapacity(int newcapacity) The ILifo interface serves to specify a special kind of data structure for storing a collection of integers. It is unique in the insertion and deletion of collection elements. An element can be added to the collection through the push method. The pop method is to remove the most recently addecd integer that was not yet removed. All ILifo methods are described as below: . public int getLength () .public boolean isEmpty() . public void push (int num) o Return the number of elements (i.e., integers) currently in the data structure. o Return true if the data structure is currently empty (i.e., has no element) o Add the passed-in integer to the collection. when the collection is full, this method should signal the caller and reject the request. public int pop () Remove the most recently added integer from the collection and return it. When the collection is empty, this method should signal the caller and reject the request. o o e int getCapacity) Return the capacity of the data structure, that is, the maximum amount of integers the data structure can hold. For example, if the capacity is 100, then the data structure can contains at most 100 integers. Once it contains 100 integers, no more elements can be added before the data structure is popped o int setcapacity(int newcapacity) is used to expand the current data structure for increasing its capacity. The implementing class has to reallocate storage for existing elements and the desired additional capacity. For example, if the capacity before calling setcapacity is 100, calling setCapacity (200) would result in increasing the total capacity to 200. This method is also responsible for copying all existing elements to the newly allocated storage without compromising the ordering and contents of the collection

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_2

Step: 3

blur-text-image_3

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

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

Students also viewed these Databases questions