Source Code
Source Code
/** System.out.println("****************************");
* Remove the most recently inserted item from the stack. System.out.println("Stack Example");
*/ System.out.println("****************************");
public void pop( ) {
if( isEmpty( ) ) ArrayStack arrayStack = new ArraySt ack();
throw new RuntimeException( "ArrayStack pop" ); arrayStack.push(new String("a"));
topOfStac k--; arrayStack.push(new String("b"));
} arrayStack.push(new String("c"));
arrayStack.push(new String("d"));
/**
* Return and remove the most recently inserted item System.out.println("Stack Elements -> a, b, c, d");
* from the stack. System.out.println("Stack LIFO -> "+arrayStack .top());
* @return the most recently inserted item in the stack. arrayStack.pop();
*/ System.out.println("POP on Stack " );
public Object topAndPop( ) { System.out.println("Stack LIFO -> "+arrayStack.top());
if( isEmpty( ) )
throw new Run timeException( "ArrayStack topAndPop" ); }}
return theArray[ topOfStack -- ];
} OUTPUT Stack Example
****************************
/** E:\User\Lathadelvi \Experiment 1>java Stack Elements -> a, b, c, d
* Insert a new item into the stack. QueueStackTester Stack LIFO -> d
* @param x the item to insert. **************************** POP on Stack
*/ Queue Exam ple Stack LIFO -> c
public void push( Object x ) { ****************************
if( topOfStack + 1 == theAr ray.length ) Queue Elements -> 1, 2, 3, 4 E:\User\Lathadelvi \Experiment 1>
doubleArray( ); Queue FIFO -> 1
theArray[ ++topOfStack ] = x; Queue removed element -> 1
} Queue FIFO -> 2
****************************