-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathStackUsingArray.java
More file actions
37 lines (34 loc) · 936 Bytes
/
StackUsingArray.java
File metadata and controls
37 lines (34 loc) · 936 Bytes
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
import java.util.*;
public class StackUsingArray {
public static void main(String[] args) {
stack s = new stack();
s.push(6);
s.push(3);
s.push(7);
System.out.println("Top of the stack before deleting any element " + s.top());
System.out.println("Size of the stack before deleting any element " + s.size());
System.out.println("The element deleted is " + s.pop());
System.out.println("Size of the stack after deleting an element " + s.size());
System.out.println("Top of the stack after deleting an element " + s.top());
}
}
class stack {
int size = 10000;
int arr[] = new int[size];
int top = -1;
void push(int x) {
top++;
arr[top] = x;
}
int pop() {
int x = arr[top];
top--;
return x;
}
int top() {
return arr[top];
}
int size() {
return top + 1;
}
}