Code Import Javautil Public Class Maxstacktest Public Static Void Main String Args Maxstac Q37159967

[1.5 mark] Add your code to the MaxStack class given below to implement a stack that supports a max method, which returns the

Code:

import java.util.*;

public class MaxStackTest {

public static void main(String[] args) {

   MaxStack<Integer> maxStack = newMaxStack<Integer>();

   // Add your code here to test allmethods of MaxStack class

}

}

class MaxStack<T extends Comparable<T>>{

// this class could use O(n) space in addition to whatis required for

// the elements themselves.

// Y could be either T or class name of an additionalclass you design

LinkedList<Y> itemList = newLinkedList<Y>();

// add your code here if needed

void push(T item) {

   // add your code here to insert itemto itemList

   //

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.