+/EE360P

distributed systems

git clone https://git.julia.blue/+/EE360P

vijaygarg1add stack and queuecccc41d

master
469 B23 linesraw
1import java.util.NoSuchElementException;
2
3public class Stack<T> {
4    Node<T> top = null;
5    
6    public synchronized void push(T value) {
7    	Node<T> node = new Node(value);
8	node.next = top;
9	top = node;
10    }
11    
12    public synchronized T pop() throws NoSuchElementException {
13		if(top == null) {
14		    throw new NoSuchElementException();
15		} else {
16                Node<T> oldTop = top;
17		top = top.next;
18		return oldTop.value;
19               }
20   
21    }
22    
23}