-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stack_Class.java
58 lines (54 loc) · 1022 Bytes
/
Stack_Class.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
50
51
52
53
54
55
56
57
58
package scope_operator_validation;
public class Stack_Class
{
int size;
char List[];
int top;
public Stack_Class(int s)
{
this.size = s;
this. List = new char[size];
this.top = -1;
}
// underflow
public boolean is_empty()
{
return top == -1;
}
//oveflow
public boolean is_full()
{
return top == List.length - 1;
}
//insertion
public void push(char num)
{
if(is_full())
{
// System.out.println(" can not add, already full");
}
else
{
top++;
List[top] = num;
}
}
//deletion
public char pop()
{
char entry = 'm';
if(is_empty())
{
//System.out.println("Stack is empty. Can not remove element.");
}
else
{
entry = List[top--];
}
return entry;
}
public char peak()
{
return List[top];
}
}