-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.java
71 lines (63 loc) · 1.56 KB
/
Stack.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// import java.util.Scanner;
public class Stack {
// int n;
static int top = -1;
static int[] Stack = new int[10];
static boolean isEmpty() {
return (top < 0);
}
static void push(int data) {
if (top >= 10) {
System.out.println("Stack OverFlow");
} else {
Stack[++top] = data;
}
}
static void pop() {
if (top < 0) {
System.out.println("Stack UnderFlow");
} else {
System.out.println(Stack[top]);
top--;
}
}
static void peep() {
if (top < 0) {
System.out.println("Stack UnderFlow");
} else {
System.out.println(Stack[top]);
}
}
static void PrintStack() {
System.out.println("Stack Elements");
for (int i = top; i > -1; i--) {
System.out.print(" " + Stack[i]);
}
System.out.println();
}
public static void main(String[] args) {
// Scanner Input = new Scanner(System.in);
// System.out.println("Enter Size Of Stack");
// int n = Input.nextInt();
push(10);
push(9);
push(8);
push(7);
push(6);
PrintStack();
pop();
pop();
// PrintStack();
push(5);
// push(4);
// peep();
// peep();
System.out.println();
PrintStack();
System.out.println("Stack Top");
peep();
// pop();
// pop();pop();pop();pop();pop();
// System.out.println(isEmpty());
}
}