-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlistaent.cpp
More file actions
63 lines (49 loc) · 1.23 KB
/
listaent.cpp
File metadata and controls
63 lines (49 loc) · 1.23 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
#include "listaent.h"
ListaEnt::ListaEnt() {
this->longitud = 0;
this->cabeza = new NodoEnt();
this->cola = new NodoEnt();
}
int ListaEnt::getLongitud() {
return this->lingitud;
}
void ListaEnt::insertarAlInicio(int entero) {
NodoEnt nodoNuevo = new NodoEnt(entero);
if (this->cabeza.getSiguiente() == null) {
this->cola.setAnterior(nodoNuevo);
} else {
nodoNuevo.setSiguiente(this->cabeza.getSiguiente());
this->cabeza.getSiguiente().setAnterior(nodoNuevo);
}
this->cabeza.setSiguiente(nodoNuevo);
this->lingitud++;
}
void ListaEnt::insertarAlFinal(int entero) {
NodoEnt nodoNuevo = new NodoEnt(entero);
if (this->cola.getAnterior() == null) {
this->cabeza.setSiguiente(nodoNuevo);
} else {
nodoNuevo.setAnterior(this->cola.getAnterior());
this->cola.getAnterior().setSiguiente(nodoNuevo);
}
this->cola.setAnterior(nodoNuevo);
this->lingitud++;
}
bool ListaEnt::estaVacia() {
if (this->lingitud == 0) {
return true;
} else {
return false;
}
}
void ListaEnt::mostrarLista() {
NodoEnt nodoAux = this->cabeza;
if (this->estaVacia()) {
cout<< "La lista está vacía" << endl;
} else {
while (nodoAux.getSiguiente() != null) {
nodoAux = nodoAux.getSiguiente();
cout<< nodoAux.getValor() << endl;
}
}
}