84 lines
1.3 KiB
C++
84 lines
1.3 KiB
C++
#include "nodo.hpp"
|
|
#include <cassert>
|
|
|
|
Nodo::Nodo(){
|
|
sig = nullptr;
|
|
ptr = nullptr;
|
|
car = ' ';
|
|
}
|
|
Nodo::~Nodo() {
|
|
delete sig;
|
|
delete ptr;
|
|
}
|
|
|
|
Nodo* Nodo::consulta(char letra) {
|
|
// implementación tal cual del método consulta del tema 3
|
|
Nodo* temp = this -> sig;
|
|
while (temp != nullptr){
|
|
if (temp -> car == letra) {
|
|
return temp -> ptr;
|
|
}
|
|
temp = temp -> sig;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void Nodo::inserta(char l) {
|
|
|
|
// implementación tal cual del método inserta del tema 3
|
|
Nodo* temp = this;
|
|
while ((temp->sig != nullptr) && (temp -> sig -> car < l)) {
|
|
temp = temp -> sig;
|
|
}
|
|
|
|
if ((temp -> sig != nullptr) && (temp -> sig -> car == l)) {
|
|
return;
|
|
}
|
|
|
|
Nodo* nuevo = new Nodo;
|
|
nuevo -> car = l;
|
|
nuevo -> sig = temp -> sig;
|
|
temp -> sig = nuevo;
|
|
nuevo -> ptr = new Nodo;
|
|
|
|
}
|
|
|
|
bool Nodo::HayMarca() {
|
|
return this -> car == '$';
|
|
}
|
|
|
|
void Nodo::PonerMarca() {
|
|
this -> car = '$';
|
|
}
|
|
|
|
void Nodo::PonerEnLista(Cuac *ref) {
|
|
if (HayMarca()) {
|
|
|
|
list<Cuac*>::iterator it;
|
|
for (it = lista.begin(); it != lista.end(); it++) {
|
|
if (!ref -> comparar(**it)) {
|
|
lista.insert(it, ref);
|
|
return;
|
|
}
|
|
}
|
|
lista.push_back(ref);
|
|
}
|
|
}
|
|
|
|
list<Cuac*> Nodo::getLista() {
|
|
return this -> lista;
|
|
}
|
|
|
|
Nodo* Nodo::getSig() {
|
|
return this -> sig;
|
|
}
|
|
|
|
Nodo* Nodo::getPtr() {
|
|
return this -> ptr;
|
|
}
|
|
|
|
char Nodo::getCar() {
|
|
return this -> car;
|
|
}
|
|
|