Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class GenericStack {
- private Node <T> top;
- private class Node<T> {
- private T data;
- private Node<T> next;
- public Node(T item) {
- data = item;
- next = null;
- }
- }
- public GenericStack () {
- top = null;
- }
- public boolean isEmpty() {
- return top = null;
- }
- public T top() {
- return top.data;
- }
- public void push(t item) {
- Node<T> n = new Node<T>(item);
- n.next = top;
- top = n;
- }
- public T pop() throws EmptyStackException{
- if ( top == null )
- throw new EmptyStackException();
- T n = top.data;
- top = top.next;
- return n;
- }
- }
Add Comment
Please, Sign In to add comment