Java Lab Exercise - 6
Java Lab Exercise - 6
Java Lab Exercise - 6
import java.util.*;
import java.util.*;
class Array
{
public static <T> void swap(T[] a, int i, int j)
{
T temp = a[i];
a[i] = a[j];
a[j] = temp;
}
class Stack<E> {
private final int size;
public Stack() {
this(10);
}
public Stack(int s) {
size = s > 0 ? s : 10;
top = -1;
public E pop() {
if (top == -1) // if stack is empty
throw new EmptyStackException("Stack is empty, cannot pop");
class MainClass {
try {
System.out.println("\nPopping elements from doubleStack");
double popValue;
while (true) {
popValue = doubleStack.pop(); // pop from doubleStack
System.out.printf("%.1f ", popValue);
}
} catch (EmptyStackException emptyStackException) {
System.err.println();
emptyStackException.printStackTrace();
}
}
}