Stack2540Array   import java .io .*; import java . util .*; public class Stack2540Array { int CAPACITY = 128; int top...

90.2K

Verified Solution

Question

Programming

Stack2540Array  

import java .io .*;
import java . util .*;
public class Stack2540Array {
int CAPACITY = 128;
int top ;
String [] stack ;
public Stack2540Array () {
stack = new String [ CAPACITY ];
top = -1;
}
1

public int size () { return top + 1; }
public boolean isEmpty () { return (top == -1); }
public String top () {
if ( top == -1)
return null ;
return stack [ top ];
}
public void push ( String element ) {
top ++;
stack [top ] = element ;
}

3.2 Dynamic Array
To save computer memory, we need to use dynamic array. In the rstversion of our stack implementation, the instance variable hasa
xed capacity, which is 128. There will be an error when the stackis bigger than 128. For bigger data, you increased the array size.But
that very long array could be wasted for smaller data.

in java please.

Answer & Explanation Solved by verified expert
4.0 Ratings (532 Votes)
SolutionJava Codeimport java io import java util public class Stack2540Array private ArrayList stack private member of typeArrayList constructor for the classpublic Stack2540Array stack new ArrayList sizeofstack function    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students