-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPileRPL.java
More file actions
110 lines (93 loc) · 1.67 KB
/
PileRPL.java
File metadata and controls
110 lines (93 loc) · 1.67 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
public class PileRPL{
private int NBOBJMAX;
private int nbObj;
private ObjEmpilable[] pile;
PileRPL(){
this(3);
}
PileRPL(int nbObjMax){
this.NBOBJMAX = nbObjMax;
this.nbObj = 0;
pile = new ObjEmpilable[nbObjMax];
}
public int push(ObjEmpilable obj){
if (this.isFull())
return 1;
pile[nbObj] = obj;
nbObj++;
return 0;
}
public ObjEmpilable pop(){
ObjEmpilable obj = pile[nbObj - 1];
nbObj--;
return obj;
}
public void drop(){
ObjEmpilable obj = pile[nbObj - 1];
nbObj--;
}
public void swap(){
ObjEmpilable tmp = pile[nbObj - 1];
pile[nbObj - 1] = pile[nbObj - 2];
pile[nbObj - 2] = tmp;
}
public void clear(){
this.nbObj = 0;
}
public boolean isEmpty(){
return (nbObj <= 0);
}
public boolean isFull(){
return (nbObj >= NBOBJMAX);
}
public int add(){
ObjEmpilable obj1 = this.pop();
ObjEmpilable obj2 = this.pop();
this.push(obj1.add(obj2));
return 0;
}
public int sou(){
ObjEmpilable obj1 = this.pop();
ObjEmpilable obj2 = this.pop();
this.push(obj2.sou(obj1));
return 0;
}
public int mul(){
ObjEmpilable obj1 = this.pop();
ObjEmpilable obj2 = this.pop();
this.push(obj2.mul(obj1));
return 0;
}
public int div(){
ObjEmpilable obj1 = this.pop();
ObjEmpilable obj2 = this.pop();
this.push(obj2.div(obj1));
return 0;
}
public int getNbObj(){
return this.nbObj;
}
public String toString(){
String pile = "";
int i = this.nbObj - 1;
while (i >= 0){
pile += "!" + this.pile[i] + "!\n";
i--;
}
pile += "+-+";
return pile;
}
public String toHTML(){
String pile = "";
int i = this.nbObj - 1;
while (i >= 0){
pile += "!" + this.pile[i] + "!</br>";
i--;
}
pile += "+-+";
return pile;
}
public ObjEmpilable[] getPile(){
return this.pile;
}
}