302
This commit is contained in:
79
nodo.cpp
79
nodo.cpp
@@ -1,22 +1,83 @@
|
||||
#include "nodo.hpp"
|
||||
#include <cassert>
|
||||
|
||||
Nodo::Nodo(){
|
||||
sig = nullptr;
|
||||
ptr = nullptr;
|
||||
car = ' ';
|
||||
}
|
||||
Nodo::~Nodo() {
|
||||
delete sig;
|
||||
delete ptr;
|
||||
}
|
||||
|
||||
Nodo* consulta(char letra);
|
||||
void inserta(char l);
|
||||
bool HayMarca();
|
||||
void PonerMarca();
|
||||
void PonerEnLista(Cuac *ref) {
|
||||
|
||||
}
|
||||
list<Cuac*> getLista() {
|
||||
return lista;
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user