Пример #1
0
        public static void Main(string[] args)
        {
            int i;

            PriorityQueue <PriorityClass> PQ = new PriorityQueue <PriorityClass>(10);

            PriorityClass[] A = new PriorityClass[5];

            A[0] = new PriorityClass(1, "Susan");
            A[1] = new PriorityClass(3, "Hannah");
            A[2] = new PriorityClass(3, "Tony");
            A[3] = new PriorityClass(7, "Pranjal");
            A[4] = new PriorityClass(1, "Alan");

            PQ.Add(new PriorityClass(6, "Brian"));
            PQ.Add(new PriorityClass(6, "Richard"));
            PQ.Add(new PriorityClass(4, "Sabine"));
            PQ.Add(new PriorityClass(7, "Wenying"));
            PQ.Add(new PriorityClass(0, "Patrick"));

            while (!PQ.Empty())
            {
                Console.WriteLine(PQ.Front().ToString());
                PQ.Remove();
            }
            Console.ReadLine();

            PQ.HeapSort(A);
            for (i = 0; i < A.Length; i++)
            {
                Console.WriteLine(A[i].ToString());
            }
            Console.ReadLine();
        }
Пример #2
0
        public int CompareTo(Object obj)
        {
            PriorityClass other = (PriorityClass)obj;   // Explicit cast

            return(priorityValue - other.priorityValue);
        }