CS计算机代考程序代写 Java package linear;

package linear;

import java.util.ArrayList; //import the class in order to use it
import java.util.NoSuchElementException;

public class StackUsingArrayList {

private ArrayList list = new ArrayList();

public void push(T v) {
list.add(v);
}

public T peek() {
return list.get(list.size()-1);
}

public T pop() throws NoSuchElementException{
if(list.size() == 0)
throw new NoSuchElementException();
return list.remove(list.size()-1);
}

public boolean isEmpty() {
return list.isEmpty();
}

public int size() {
return list.size();
}

public static void main(String[] args) {
StackUsingArrayList stack = new StackUsingArrayList();
stack.push(“!”);
stack.push(“CS112″);
stack.push(” “);
stack.push(“to”);
stack.push(” “);
stack.push(“Welcome”);
while (!stack.isEmpty()) {
System.out.print(stack.pop()); //Welcome to CS112
}
}
}