-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFila.java
More file actions
40 lines (35 loc) · 742 Bytes
/
Fila.java
File metadata and controls
40 lines (35 loc) · 742 Bytes
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
public class Fila{
private int[] valores;
private int primeiro;
private int ultimo;
private int total;
public Fila(){
valores = new int[10];
primeiro = 0;
ultimo = 0;
total = 0;
}
public void inserir(int elemento){
if (isFull()){
throw new RuntimeException("Fila lotada ");
}
valores[ultimo]= elemento;
ultimo = (ultimo + 1) % valores.length;
total++;
}
public int retirar(){
if (isEmpty()){
throw new RuntimeException("Fila vazia ");
}
int elemento = valores[primeiro];
primeiro = (primeiro + 1) % valores.length;
total--;
return elemento;
}
public boolean isEmpty(){
return total==0;
}
public boolean isFull(){
return total==valores.length;
}
}