Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- class AB{
- public:
- typedef struct{
- char letra;
- int frecuencia;
- bool bit;
- bool vacio;
- }tValor;
- AB();
- AB(const AB&);
- const AB& operator=(const AB&);
- ~AB();
- bool ABVacio();
- bool Insertar(tValor);
- bool Eliminar (char);
- string InOrden();
- string PreOrden();
- private:
- tValor valor;
- AB *hijoDerecho;
- AB *hijoIzquierdo;
- bool Vaciar();
- }
- bool AB::ABVacio() {
- if(hijoIzquierdo == NULL && hijoDerecho == NULL && valor.vacio == 1)
- return 1;
- else
- return 0;
- }
- bool AB::Insertar(tValor nuevo){
- if(self.valor.vacio == 1) {
- self.valor.bit = nuevo.bit;
- self.valor.letra = nuevo.letra;
- self.valor.frecuencia = nuevo.frecuencia;
- self.valor.vacio = 0;
- return 1;
- } else if (nuevo.frecuencia < self.valor.frecuencia)
- hijoIzquierdo->Insertar(nuevo);
- else if(nuevo.frecuencia > self.valor.frecuencia)
- hijoDerecho->Insertar(nuevo);
- else
- return 0;
- }
- bool AB::Eliminar(char borrar){
- if(self.valor.letra == borrar)
- self.valor.vacio=1;
- else if (nuevo.frecuencia < self.valor.frecuencia)
- hijoIzquierdo->Eliminar(nuevo);
- else if(nuevo.frecuencia > self.valor.frecuencia)
- hijoDerecho->Eliminar(nuevo);
- else
- return 0;
- }
- string AB::InOrden (){
- if (self == NULL){
- string izqstr = hijoIzquierdo->InOrden();
- izqstr.append (self.valor.letra);
- string derstr = hijoDerecho->InOrden();
- izqstr.append (derstr);
- return izqstr;
- }
- else
- return string();
- }
- int main ()
- {
- return 0;
- }
Add Comment
Please, Sign In to add comment