Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- NOTA requiere heap.h y heap.cpp
- 1.- ordene numeros con un heap
- 2.- ordene personas con un heap (persona es string de nombre)
- 3.-
- 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
- */
- #include <iostream>
- #include "heap.h"
- #include "animal.h"
- using namespace std;
- int main() {
- cout << "Ejercicio 3:\n";
- Animal verde;
- Animal azul;
- Animal amarillo;
- Animal cafe;
- Animal uno_cualquiera;
- verde.setNombre("rana");
- verde.setVelocidad(3);
- azul.setNombre("ballena");
- azul.setVelocidad(12);
- amarillo.setNombre("leon");
- amarillo.setVelocidad(40);
- cafe.setNombre("caballo");
- cafe.setVelocidad(25);
- Heap<Animal> heap_de_animales;
- heap_de_animales.agregar(amarillo, amarillo.getVelocidad());
- heap_de_animales.agregar(cafe, cafe.getVelocidad());
- heap_de_animales.agregar(verde, verde.getVelocidad());
- heap_de_animales.agregar(azul, azul.getVelocidad());
- while (!heap_de_animales.vacio()) {
- heap_de_animales.extraer().ver();
- // uno_cualquiera.ver();
- }
- cout << endl << endl;
- cout << "Ejercicio 1:\n";
- int valor;
- Heap<int> heap_de_enteros;
- heap_de_enteros.agregar(4,4);
- heap_de_enteros.agregar(7,7);
- heap_de_enteros.agregar(2,2);
- heap_de_enteros.agregar(5,5);
- while (!heap_de_enteros.vacio()) {
- valor = heap_de_enteros.extraer();
- cout << valor << endl;
- }
- cout << endl << endl;
- cout << "Ejercicio 2:\n";
- string nombre;
- Heap<string> heap_de_personas;
- heap_de_personas.agregar("pedro",4);
- heap_de_personas.agregar("juan",2);
- heap_de_personas.agregar("jose",2);
- heap_de_personas.agregar("diego",5);
- heap_de_personas.agregar("maria",1);
- while (!heap_de_personas.vacio()) {
- nombre = heap_de_personas.extraer();
- cout << nombre << endl;
- }
- cout << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement