-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackImplt.java
More file actions
66 lines (53 loc) · 1.23 KB
/
Copy pathStackImplt.java
File metadata and controls
66 lines (53 loc) · 1.23 KB
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
import java.util.Stack;
public class StackImplt {
static int max;
static public int stack[];
static int top=-1;
static int val;
public static void push(int data)
{
if(top==max-1)
{
System.out.println("Stack is Overflow you can not insert element...");
return;
}
top+=1;
stack[top]=data;
}
public static int pop()
{
if(top==-1)
{
System.out.println("Stack is underflow first insert elements in stack");
return -1;
}
val=stack[top];
top-=1;
return val;
}
public static int peek()
{
if(top==-1)
{
System.out.println("Stack is underflow first insert elements in stack");
return -1;
}
val=stack[top];
return val;
}
public static void print()
{
if(top==-1)
{
System.out.println("Stack is underflow first insert elements in stack");
return;
}
for(int i=0;i<=top;i++)
{
System.out.print(stack[i]+" ");
}
System.err.println();
}
public static void main(String[] args) {
}
}