-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClsListaS.java
More file actions
109 lines (85 loc) · 2.5 KB
/
ClsListaS.java
File metadata and controls
109 lines (85 loc) · 2.5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import javax.swing.DefaultListModel;
public class ClsListaS {
ClsNodoS inicio, fin;
public ClsListaS() {
inicio = null;
fin = null;
}
public void insertaS(String dato) {
if (inicio == null && fin == null) { // vacia
// inicio = fin = new ClsNodo(dato);
inicio = new ClsNodoS(dato);
fin = inicio;
} else {
fin.setSiguiente(new ClsNodoS(fin, dato, null));
fin = fin.getSiguiente();
}
}
DefaultListModel modeloinicio = new DefaultListModel();
DefaultListModel modelofin = new DefaultListModel();
public void iniciofin() {
modeloinicio.clear();
ClsNodoS aux = inicio;
if (inicio != null) { // no este vacia
while (aux.getSiguiente() != null) { // mientras haya elementos despues
modeloinicio.addElement(aux.getDato()); // se agrega el dato
aux = aux.getSiguiente(); // se recorre al siguiente dato
}
modeloinicio.addElement(aux.getDato());
}
}
public void fininicio() {
modelofin.clear();
ClsNodoS aux = fin;
if (fin != null) { // no este vacia
while (aux.getAnterior() != null) { // mientras haya elementos antes
modelofin.addElement(aux.getDato()); // se agrega el dato
aux = aux.getAnterior(); // se recorre al dato anterior
}
modelofin.addElement(aux.getDato());
}
}
public void limpiar() {
modelofin.clear();
}
public String dato;
public String borrar(int indice) {
ClsNodoS aux = inicio;
for (int i = 0; i < indice; i++) {
aux = aux.getSiguiente();
}
dato = aux.getDato();
if (inicio == null) {
}
// unico dato
if (aux.getSiguiente() == null && aux.getAnterior() == null) {
inicio = fin = null; // lista vacia
}
// primer dato
else if (aux == inicio) {
// cambiamos el inicio anterior por el del siguiente nodo
inicio = inicio.getSiguiente();
// ponemos nulo el inicio anterior
inicio.setAnterior(null);
}
// ultimo dato
else if (aux == fin) {
// me situo en el anterior y pongo el siguiente nulo, lo que lo vuelve el final
fin.getAnterior().setSiguiente(null);
fin = fin.getAnterior();
}
// cualquier dato
else if (aux.getSiguiente() != null && aux.getAnterior() != null) {
aux.getAnterior().setSiguiente(aux.getSiguiente());
aux.getSiguiente().setAnterior(aux.getAnterior());
}
return dato;
}
public String getdato(int indice) {
ClsNodoS aux = inicio;
for (int i = 0; i < indice; i++) {
aux = aux.getSiguiente();
}
return aux.getDato();
}
}