-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.java
More file actions
52 lines (44 loc) · 1.11 KB
/
Copy pathStack.java
File metadata and controls
52 lines (44 loc) · 1.11 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
public class Stack {
private int[] values;
private int front;
private int size;
public Stack(int size){
this.values = new int[size];
this.front = 0;
this.size = size;
}
public int[] get_values(){
return this.values;
}
public int get_front(){
return this.front;
}
public int get_size(){
return this.size;
}
public boolean stack_empty(){
if (this.front == 0 && this.size == 0) {
return true;
} else {
return false;
}
}
public void push(int element){
this.size = this.size + 1;
this.values[this.front] = element;
this.front = this.front + 1;
}
public int pop(){
if (this.stack_empty()){
throw new IndexOutOfBoundsException();
} else {
this.front = this.front - 1;
return this.values[this.front + 1];
}
}
public void empty(int size){
this.values = new int[size];
this.front = 0;
this.size = size;
}
}