Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

********Both problems are related*************** ********Java Code Required************** Java Problem 1: Java: underlying implementation of Javas ArrayList. It uses a regular Java array to store data

********Both problems are related*************** ********Java Code Required**************

Java Problem 1:

Java: underlying implementation of Javas ArrayList. It uses a regular Java array to store data and resizes to a larger array once it is full. Implement a stack in a class called MyStack that uses an array to store data and resizes the array when necessary. All methods should run in constant time, except when the array must be resized (this is still amortized constant time). NOTE: Your class must implement MyStackInterface for full credit. You are not allowed to use any List object as your instance variable. You are only allowed to use arrays as your data retaining instance variable. Your MyStack must be generic as well. Note: For this problem use the following Interface:-

public interface MyStackInterface { public void push(T x);//insert or push into the stack public T pop(); // Pop public T peek(); // Top public boolean isEmpty();// to check if the array is empty public int size();// returns how many items are im the stack }

Problem 2: in Java Build a queue out of two completely separate stacks, S1 and S2. Enqueue operations happen by pushing the data on to stack 1. Dequeue operations are completed with a pop from stack 2. Obviously you will have to find some way to get the input stack information over to the output stack. Your job is to figure out how and when to do that, using only push and pop operations. Write a class TwoStackQueue that provides the Queue Abstrackt Data Type (by implementing the MyQueueInterface) using two stacks. Your class should explicitly implement the interface provided above. Since the interface is generic, your class should be as well. Provide all methods specified in the interface. Your class should not use any additional memory to store the data in the queue except for the two stacks. For your stacks, use the MyStack class that you implemented in the first problem. All methods must run in constant time, except for one, which is allowed to run in linear time occassionally. Note: For Problem 2 use this Interface:-

public interface TwoStackQueueInterface {

public void enqueue(T x); public T dequeue(); public int size(); public boolean isEmpty(); }

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions