-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFila.java
More file actions
50 lines (39 loc) · 958 Bytes
/
Copy pathFila.java
File metadata and controls
50 lines (39 loc) · 958 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
41
42
43
44
45
46
47
48
49
50
public class Fila <X>
{
private Object[] vetor;
private int inicio=0, fim=0, qtd=0;
public Fila (int tamanho) throws Exception
{
if (tamanho<1)
throw new Exception ("Tamanho invalido");
this.vetor = new Object [tamanho];
}
public void guarde (X x) throws Exception
{
if (x==null)
throw new Exception ("Informacao ausente");
if (this.qtd == this.vetor.length)
throw new Exception ("Nao cabe mais nada");
this.vetor[this.fim] = x;
this.fim = this.fim<this.vetor.length?this.fim+1:0;
this.qtd++;
}
public X getItem () throws Exception
{
if (this.qtd==0)
throw new Exception ("Nada guardado");
return (X)this.vetor[this.inicio];
}
public void removaItem () throws Exception
{
if (this.qtd==0)
throw new Exception ("Nada guardado");
this.vetor[this.inicio] = null;
this.inicio = this.inicio<this.vetor.length?this.inicio+1:0;
this.qtd--;
}
public int Tamanho()
{
return qtd;
}
}