Need a java test program that goes with this code. class AStack implements Stack
ID: 3651716 • Letter: N
Question
Need a java test program that goes with this code.class AStack implements Stack // Array based stack class
{
// Data members
private int size; // Maximum size of Stack
private int top; // Index for the top element
private Object [ ] element; // Array containing stack elements
// Constructors and helper method setup
public AStack( ) // Constructor: default size
{
setup( size );
}
public AStack( int size ) // Constructor: specific size
{
setup( size );
}
// Class methods
private void setup( int size ) // Called bu constructors only
{
this.size = size + 1;
this.top = 0;
this.element = new Object[ this.size ];
}
public void clear( ) // Remove all Objects from Stack
{
this.top = 0;
}
public void push( Object newElem ) // Push Object onto stack
{
if ( this.top < this.size )
{
this.element[ this.top ] = newElem;
this.top++;
} else
throw new IllegalArgumentException( "Stack Overflow");
}
public Object pop( ) // Pop Object from top of stack
{
if ( !isEmpty( ) )
{
return this.element[ --this.top ];
} else
throw new IllegalArgumentException( "Empty Stack" );
}
public boolean isEmpty( ) // Return true if stack is empty
{
return ( this.top == 0 );
}
public boolean isFull( ) // Return true if stack is full
{
int max = this.size - 1;
return ( this.top == max );
}
public void showStructure( )
{
int d;
for ( d = 0; d <= this.top; d++ )
{
if ( element[ d ] != null )
System.out.print( element[ d ] + " " );
}
}
} // class AStack
Explanation / Answer
answer:::::::::::::::: helpfull void pop(void) { char ch; do { if(empty() == 1) { printf(" Stack Empty "); break; } else { printf(" %d has been popped !",s.stack[s.top]); s.top = s.top - 1; } printf(" Do you Want To Pop Out More?[y/n]"); flushall(); ch = getch(); } while(ch == 'Y' ch == 'y'); } void display(void) { int i; clrscr(); if(empty() == 1) printf(" Stack Empty!!!"); else { printf("Displaying Stack............ "); for(i = s.top; i>0;i--) printf("%d",s.stack[i]); }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.