Created by Marc Faulhaber
over 8 years ago
|
||
public Stack{Object[] stack;int topOfStack;Semaphor mutex = new Semaphor(1);Semaphor sPush;Semaphor sPop;public Stack(int max){Stack = new Stack(max);sPush = new Semaphor(max);sPop = new Semaphor(0);}public void push(Object el){sPush.p();mutex.p();Stack[topOfStack] = el;topOfStack++;mutex.v();sPop.v();}public Object pop(){sPop.p();mutex.p();Object o1 = Stack[topOfStack];sPush.v();mutex.v();return o1;}}
Want to create your own Notes for free with GoConqr? Learn more.