Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Heap<Vehiculo> heap = new Heap<Vehiculo>((element, element2) => element.Nombre.CompareTo(element2.Nombre));

            Console.WriteLine("***HEAP DE VEHÍCULOS***");

            heap.Insert(new Vehiculo(200, "Honda"));
            heap.Insert(new Vehiculo(220, "Ferrari"));
            heap.Insert(new Vehiculo(230, "Audi"));
            heap.Insert(new Vehiculo(210, "Suzuki"));
            heap.Insert(new Vehiculo(120, "Toyota"));
            heap.Insert(new Vehiculo(130, "Ford"));
            heap.Insert(new Vehiculo(320, "Porsche"));

            Console.WriteLine(heap);

            Console.WriteLine($"RemoveMin: {heap.RemoveMin.Nombre}");
            Console.WriteLine($"RemoveMin: {heap.RemoveMin.Nombre}");
            Console.WriteLine($"RemoveMin: {heap.RemoveMin.Nombre}");
            Console.WriteLine($"RemoveMin: {heap.RemoveMin.Nombre}");
            Console.WriteLine($"RemoveMin: {heap.RemoveMin.Nombre}");

            Console.WriteLine(heap);

            //Console.WriteLine(heap);

            Console.WriteLine();

            Console.WriteLine("***HEAPIFY***");

            List<int> list = new List<int>() { 14, 5, 8, 25, 9, 11, 17, 16, 15, 4, 12, 6, 7, 23, 20 };

            Heap<int> newHeap = Heap<int>.Heapify(list, (element, element2) => element.CompareTo(element2));

            Console.WriteLine(newHeap);

            Console.WriteLine();

            Console.WriteLine("***HEAPSORT***");

            Heap<int>.HeapSort(list, (element, element2) => element.CompareTo(element2));

            Console.Write("[ ");

            list.ForEach(element => Console.Write($"{element} "));

            Console.WriteLine("]");

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //100, 30, 20, 1, 3, 10, 15
            var arr  = new int[] { 10, 9, 8, 7, 43, 235, 256, 977, 4 };
            var heap = new Heap <int>();

            foreach (var item in arr)
            {
                heap.Insert(item);
            }

            heap.HeapSort(heap, heap.size() - 1);
            //var max = heap.Peek();
            //heap.Increase(8, 40);
            //Get and delete max heap
            //var maxDeleted = heap.DeleteMax();
        }