Guest User

Untitled

a guest
Nov 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. class AB{
  5. public:
  6. typedef struct{
  7. char letra;
  8. int frecuencia;
  9. bool bit;
  10. bool vacio;
  11. }tValor;
  12.  
  13. AB();
  14. AB(const AB&);
  15. const AB& operator=(const AB&);
  16. ~AB();
  17. bool ABVacio();
  18. bool Insertar(tValor);
  19. bool Eliminar (char);
  20. string InOrden();
  21. string PreOrden();
  22.  
  23. private:
  24. tValor valor;
  25. AB *hijoDerecho;
  26. AB *hijoIzquierdo;
  27.  
  28. bool Vaciar();
  29. }
  30.  
  31. bool AB::ABVacio() {
  32.  
  33. if(hijoIzquierdo == NULL && hijoDerecho == NULL && valor.vacio == 1)
  34. return 1;
  35. else
  36. return 0;
  37. }
  38.  
  39. bool AB::Insertar(tValor nuevo){
  40.  
  41. if(self.valor.vacio == 1) {
  42. self.valor.bit = nuevo.bit;
  43. self.valor.letra = nuevo.letra;
  44. self.valor.frecuencia = nuevo.frecuencia;
  45. self.valor.vacio = 0;
  46. return 1;
  47. } else if (nuevo.frecuencia < self.valor.frecuencia)
  48. hijoIzquierdo->Insertar(nuevo);
  49. else if(nuevo.frecuencia > self.valor.frecuencia)
  50. hijoDerecho->Insertar(nuevo);
  51. else
  52. return 0;
  53. }
  54.  
  55. bool AB::Eliminar(char borrar){
  56.  
  57. if(self.valor.letra == borrar)
  58. self.valor.vacio=1;
  59. else if (nuevo.frecuencia < self.valor.frecuencia)
  60. hijoIzquierdo->Eliminar(nuevo);
  61. else if(nuevo.frecuencia > self.valor.frecuencia)
  62. hijoDerecho->Eliminar(nuevo);
  63. else
  64. return 0;
  65. }
  66.  
  67. string AB::InOrden (){
  68.  
  69. if (self == NULL){
  70. string izqstr = hijoIzquierdo->InOrden();
  71. izqstr.append (self.valor.letra);
  72. string derstr = hijoDerecho->InOrden();
  73. izqstr.append (derstr);
  74. return izqstr;
  75. }
  76. else
  77. return string();
  78. }
  79.  
  80. int main ()
  81. {
  82. return 0;
  83. }
Add Comment
Please, Sign In to add comment