-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack-java
49 lines (47 loc) · 1008 Bytes
/
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
import java.io.*;
import java.util.*;
class Stack{
static final int max=1000;
int top;
int stack[]=new int[max];
boolean isEmpty(){
return (top==-1);
}
boolean isFull(){
return (top==max);
}
Stack(){
top=-1;
}
boolean push(int x){
if(isFull())
{System.out.println("Stack Overflow");
return false;}
else
{
stack[++top]=x;
System.out.println(x + " pushed into stack");
return true;
}
}
int pop(){
if(isEmpty())
return 0;
else
{
int a=stack[--top];
return a;
}
}
};
class Main{
public static void main(String args[]){
Stack s=new Stack();
s.push(10);
s.push(20);
s.push(30);
s.push(40);
System.out.println(s.pop()+" poped from stack");
System.out.println(s.pop()+" poped from stack");
}
};