-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stack.java
70 lines (68 loc) · 1.92 KB
/
Stack.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
59
60
61
62
63
64
65
66
67
68
69
70
package St;
import java.util.ArrayList;
public class Stack {
private ArrayList<Integer> stack = null;//сам стек, с которого будут сниматься числа для операций
private ArrayList<num> numbers= null;//все числа, определенные DEFINE.
private ArrayList<String> lineParameter = null;
{
stack = new ArrayList<Integer>();
numbers = new ArrayList<num>();
}
public void AddNum(num n) {
boolean Added = false;
int ind = 0;
for (num number : numbers) {
if (number.equals(n)) {
Added = true;
break;
}
ind++;
}
if(!Added)
numbers.add(n);
else
numbers.get(ind).b = n.b;
}
public void AddToStack(int n){
stack.add(n);
}
public void DeleteFromStack(){
stack.remove(stack.size() - 1);
}
public int getLastInStack(){
return stack.get(stack.size() - 1);
}
public int getNumbersSize(){
return numbers.size();
}
public int getStackSize(){
return stack.size();
}
public void setNumStr(ArrayList<String> a){
lineParameter = a;
}
public ArrayList<String> getNumStr() {return lineParameter;}
public int getInt(num n){
return numbers.get(numbers.indexOf(n)).b;
}
public int getInt(int n){
return numbers.get(n).b;
}
public num getNum(num n){
return numbers.get(numbers.indexOf(n));
}
public void printNums(){
int c = 0;
while (c < numbers.size()) {
System.out.println(numbers.get(c).print());
c++;
}
}
public void printStack(){
int c = 0;
while (c < stack.size()) {
System.out.println(stack.get(c));
c++;
}
}
}