-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMinhaLista.java
More file actions
52 lines (42 loc) · 1.13 KB
/
MinhaLista.java
File metadata and controls
52 lines (42 loc) · 1.13 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
package AED1.Exercicios.TrabalhoFractal2;
public class MinhaLista<T> {
private Celula head;
private Celula tail;
private long tamanho;
class Celula {
T item;
Celula prox;
}
public MinhaLista() {
head = new Celula();
tail = head;
tamanho = 0;
}
public boolean isVazia() {
return head == tail;
}
public void insereNoFinal(T item) {
if (item == null) {
throw new IllegalArgumentException("Item com valor nulo!!");
} else {
tail.prox = new Celula();
tail = tail.prox;
tail.item = item;
tamanho++;
}
}
public long getTamanho() {
return tamanho;
}
public T get(long indice) {
Celula aux = head.prox;
if (isVazia() || indice >= tamanho || indice < 0) {
throw new IndexOutOfBoundsException("Tamanho do vetor inválido!!");
} else {
for (int i = 0; i < indice; i++) {
aux = aux.prox;
}
return aux.item;
}
}
}