Advertisement
fabgonber

ejemplos_de_heap

Nov 4th, 2020 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.99 KB | None | 0 0
  1. /*
  2.     NOTA requiere heap.h y heap.cpp
  3.    
  4.     1.- ordene numeros con un heap
  5.     2.- ordene personas con un heap (persona es string de nombre)
  6.     3.-
  7.       De un animal se sabe su nombre y su velocidad, cree la clase animal, luego de eso en su main haga 5 animales con distintas velocidades y ordénelos por velocidad usando un heap
  8. */
  9.  
  10. #include <iostream>
  11. #include "heap.h"
  12. #include "animal.h"
  13.  
  14. using namespace std;
  15.  
  16. int main() {
  17.  
  18.   cout << "Ejercicio 3:\n";
  19.   Animal verde;
  20.   Animal azul;
  21.   Animal amarillo;
  22.   Animal cafe;
  23.   Animal uno_cualquiera;
  24.  
  25.   verde.setNombre("rana");
  26.   verde.setVelocidad(3);
  27.   azul.setNombre("ballena");
  28.   azul.setVelocidad(12);
  29.   amarillo.setNombre("leon");
  30.   amarillo.setVelocidad(40);
  31.   cafe.setNombre("caballo");
  32.   cafe.setVelocidad(25);
  33.  
  34.   Heap<Animal> heap_de_animales;
  35.   heap_de_animales.agregar(amarillo, amarillo.getVelocidad());
  36.   heap_de_animales.agregar(cafe, cafe.getVelocidad());
  37.   heap_de_animales.agregar(verde, verde.getVelocidad());
  38.   heap_de_animales.agregar(azul, azul.getVelocidad());
  39.  
  40.  
  41.  
  42.   while (!heap_de_animales.vacio()) {
  43.         heap_de_animales.extraer().ver();
  44.         // uno_cualquiera.ver();
  45.   }
  46.  
  47.  
  48.   cout << endl << endl;
  49.   cout << "Ejercicio 1:\n";
  50.   int valor;
  51.  
  52.  
  53.   Heap<int> heap_de_enteros;
  54.   heap_de_enteros.agregar(4,4);
  55.   heap_de_enteros.agregar(7,7);
  56.   heap_de_enteros.agregar(2,2);
  57.   heap_de_enteros.agregar(5,5);
  58.  
  59.   while (!heap_de_enteros.vacio()) {
  60.         valor = heap_de_enteros.extraer();
  61.         cout << valor << endl;
  62.   }
  63.  
  64.   cout << endl << endl;
  65.   cout << "Ejercicio 2:\n";
  66.   string nombre;
  67.   Heap<string> heap_de_personas;
  68.   heap_de_personas.agregar("pedro",4);
  69.   heap_de_personas.agregar("juan",2);
  70.   heap_de_personas.agregar("jose",2);
  71.   heap_de_personas.agregar("diego",5);
  72.   heap_de_personas.agregar("maria",1);
  73.  
  74.   while (!heap_de_personas.vacio()) {
  75.         nombre = heap_de_personas.extraer();
  76.         cout << nombre << endl;
  77.   }
  78.  
  79.   cout << endl << endl;
  80.  
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement