SHOW:
|
|
- or go back to the newest paste.
| 1 | package xlot; | |
| 2 | import java.util.Scanner; | |
| 3 | import java.util.Arrays; | |
| 4 | public class Xlot | |
| 5 | {
| |
| 6 | public int size; | |
| 7 | public int[] stack; | |
| 8 | public int tos; | |
| 9 | Xlot() | |
| 10 | {
| |
| 11 | ||
| 12 | } | |
| 13 | Xlot(int s) | |
| 14 | {
| |
| 15 | size=s; | |
| 16 | stack=new int[size]; | |
| 17 | tos=-1; | |
| 18 | } | |
| 19 | public void push(int j) | |
| 20 | {
| |
| 21 | stack[++tos]=j; | |
| 22 | } | |
| 23 | public int pop() | |
| 24 | {
| |
| 25 | return stack[tos--]; | |
| 26 | } | |
| 27 | public int peek() | |
| 28 | {
| |
| 29 | return stack[tos]; | |
| 30 | } | |
| 31 | public boolean isFull() | |
| 32 | {
| |
| 33 | return (tos==size-1); | |
| 34 | } | |
| 35 | public boolean isEmpty() | |
| 36 | {
| |
| 37 | return(tos==-1); | |
| 38 | } | |
| 39 | public static void main(String[] args) | |
| 40 | {
| |
| 41 | System.out.println("enter stack size : ");
| |
| 42 | Scanner i = new Scanner(System.in); | |
| 43 | int temp1=i.nextInt(); | |
| 44 | Xlot ob = new Xlot(temp1); | |
| 45 | ob.push(1); | |
| 46 | ob.push(100); | |
| 47 | ob.push(200); | |
| 48 | ||
| 49 | while(!ob.isEmpty()) | |
| 50 | {
| |
| 51 | System.out.println(""+ob.pop());
| |
| 52 | } | |
| 53 | } | |
| 54 | } |