-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackInterface.java
More file actions
59 lines (59 loc) · 890 Bytes
/
Copy pathStackInterface.java
File metadata and controls
59 lines (59 loc) · 890 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
interface Stack
{
public void push(int e);
public int pop();
public int peak();
public int isEmpty();
public int isFull();
}
class MyStack implements Stack
{
private int top;
private int[] s;
public MyStack(int size)
{
this.top = -1;
this.s = new int[size];
}
public int isEmpty()
{
if(this.top == -1)
return 1;
else
return 0;
}
public int isFull()
{
if(top == (s.length -1))
return 1;
else
return 0;
}
public int peak()
{
return (this.s[this.top]);
}
public int pop()
{
return (s[top--]);
}
public void push(int item)
{
s[++top] = item;
}
}
class StackInterface
{
public static void main(String[] args)
{
MyStack obj = new MyStack(4);
if(obj.isFull() != 1)
obj.push(10);
else
System.out.println("Stack is Full");
if(obj.isEmpty() == 1)
System.out.println("Stack is Empty");
else
System.out.println("Top item = " + obj.peak());
}
}