public class Stack { int arr[]; private static final int DEFAULT_CAPACITY = 10; public static int top = -1; public Stack() { arr = new int[DEFAULT_CAPACITY]; } public Stack(int size) { arr = new int[size]; } public void push(int data) { arr[++top] = data; } public int pop() { return arr[top--]; } public int peek() { return arr[top]; } public boolean isEmpty() { if(top==-1) return true; return false; }}Read full article from Coding Recipies: Stack
No comments:
Post a Comment