-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayStack.java
58 lines (46 loc) · 880 Bytes
/
ArrayStack.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
package com.topcoder.easy;
public class ArrayStack {
int size=0;
int top =-1;
int max_size =10;
int arr[] = new int[max_size] ;
public void push(int n)
{
if(top == max_size-1 )
{
System.out.println("Stack is full");
return;
}
top++;
arr[top] =n;
size++;
}
public void pop()
{
if(top ==-1)
{
System.out.println("Stack is empty");
return;
}
System.out.println("Popped element is :" +arr[top]);
top--;
size--;
}
public void display()
{
for(int i =0 ; i<=top ;i++)
{
System.out.println(arr[i]);
}
}
public static void main(String[] args) {
ArrayStack as = new ArrayStack();
as.push(1);
as.push(2);
as.push(3);
as.pop();
as.pop();
System.out.println("After Popping");
as.display();
}
}