-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStack.java
More file actions
58 lines (53 loc) · 1.05 KB
/
Copy pathMyStack.java
File metadata and controls
58 lines (53 loc) · 1.05 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
package com.Sayan;
public class MyStack {
static final int Max = 7;
int top;
int a[] = new int[Max];
MyStack ()
{
top = -1;
}
boolean push (int data){
if(top >= (Max-1))
{
System.out.println ("Stack Overflow ");
return false;
}
else {
top = top+1;
a[top] = data;
System.out.println ("Data added to stack");
return true;
}
}
int pop(){
if (top==-1){
System.out.println ("Stack is empty");
return 0;
}
else {
int x = a[top];
top = top -1;
return x;
}
}
int peek() {
if (top == -1){
System.out.println ("Stack is empty");
return 0;
}
else {
int x = a[top];
return x;
}
}
boolean isEmpty(){
return (top<0);
}
boolean isFull(){
return (top>=Max-1);
}
int size (){
return (top+1);
}
}