|
|
Description
This applet demonstrates the basic operations on a stack data structure.
The operations of "Push" and "Pop" take O(1) time.
Code
(An array-based stack)
|
public void push(int val){ s[++tos]=val; } public void pop(){ if(!isEmpty()) tos--; } public int top(){ return s[tos]; } public boolean isEmpty(){ return (tos==-1)? true:false; } |