-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColasGenericas.java
More file actions
63 lines (56 loc) · 1.48 KB
/
ColasGenericas.java
File metadata and controls
63 lines (56 loc) · 1.48 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
package colass;
public class ColasGenericas <T>{
private T Esquina[];
private int Frente;
private int Siguiente;
@SuppressWarnings("uncheked")
public ColasGenericas(int N){
Esquina = (T[])new Object [N];
//Posicion inicial de Siguiente
Siguiente = 0;
//Posicion inicial de Frente
Frente = -1;
}
public boolean colaLlena(){
if(Siguiente == Esquina.length){
return true;
}else{
return false;
}
}
public void encolar(T Num) throws ExcepcionColaLlena{
//Si la cola esta vacia
//reset
if (colaVacia()){
// System.out.println("Reset");
Frente = -1;
Siguiente = 0;
}
if (colaLlena()){
throw new ExcepcionColaLlena();
}
Esquina[Siguiente] = Num;
Siguiente++;
//Cuando apenas agregue un elemento
if(Siguiente == 1){
Frente = 0;
}
}
public boolean colaVacia(){
if (Frente == Siguiente){
return true;
}else if (Frente == -1){
return true;
} else {
return false;
}
}
public T sacar() throws ExcepcionColaVacia{
if (colaVacia()){
throw new ExcepcionColaVacia();
}
T valor = Esquina[Frente];
Frente++;
return valor;
}
}