Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Stack implements StackADT {
- private LinkedList<Object> stack;
- Stack () {
- this.stack = new LinkedList<Object>();
- }
- public boolean empty() {
- return (this.size() == 0);
- }
- public int size() {
- return this.stack.size();
- }
- public Object peek() throws EmptyStackException {
- if(!this.empty()) {
- return this.stack.getLast();
- } else {
- throw new EmptyStackException();
- }
- }
- public Object pop() throws EmptyStackException {
- if(!this.empty()) {
- return this.stack.removeLast();
- } else {
- throw new EmptyStackException();
- }
- }
- public void push(Object item) {
- this.stack.add(item);
- }
- }
Add Comment
Please, Sign In to add comment