-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMystack.java
More file actions
60 lines (57 loc) · 960 Bytes
/
Copy pathMystack.java
File metadata and controls
60 lines (57 loc) · 960 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package day31;
import java.util.*;
class MyStack{
int size=5;
int data[]=new int[size];
int top=-1;
boolean push(int add) {
if(top == size-1) {
System.out.println("stack is full");
return false;
}
else {
top++;
data[top]=add;
}
return true;
}
int pop() {
if(top==-1) {
System.out.println("stack is empty");
return -111;}
else {
int add=data[top];
top--;
return add;
}
}
void printStack()
{
for(int k: data)
System.out.println(k);
}
boolean isEmpty() {
if(top==-1) {
return true;
}
return false;
}
}
public class Mystack {
public static void main(String[] args) {
MyStack stack=new MyStack();
stack.push(10);
stack.push(20);
stack.push(30);
stack.push(40);
stack.push(50);
stack.push(60);
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
int ans=stack.pop();
System.out.println(ans);
}
}