Ejemplo n.º 1
0
        public static void Main(string[] arg)
        {
            string filename = "words3.txt";

            string[] a = Util.readWords(filename);

            MaxPQ <string> pqMax = new MaxPQ <string>();

            foreach (var item in a)
            {
                pqMax.insert(item);
            }
            // se vor afisa cuvintele in ordine descrescatoare
            Console.WriteLine("MaxPQ");
            while (!pqMax.isEmpty())
            {
                Console.WriteLine(pqMax.delMax());
            }


            MinPQ <string> pqMin = new MinPQ <string>();

            foreach (var item in a)
            {
                pqMin.insert(item);
            }
            // se vor afisa cuvintele in ordine crescatoare
            Console.WriteLine("\nMinPQ");
            while (!pqMin.isEmpty())
            {
                Console.WriteLine(pqMin.delMin());
            }
        }
Ejemplo n.º 2
0
        public IEnumerator <Key> GetEnumerator()
        {
            MinPQ <Key> copy = new MinPQ <Key>(1);

            for (int i = 1; i <= N; i++)
            {
                copy.insert(pq[i]);
            }
            while (!copy.isEmpty())
            {
                yield return(copy.delMin());
            }
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            int         M  = 5;
            MinPQ <int> pq = new MinPQ <int>(M + 1);

            //StreamReader fs = new StreamReader("tinyW.txt");
            //StreamReader fs = new StreamReader("tinyT.txt");
            //StreamReader fs = new StreamReader("largeW.txt");
            StreamReader fs = new StreamReader("largeT.txt");
            string       line;

            while (!fs.EndOfStream)
            {
                line = fs.ReadLine();
                pq.insert(int.Parse(line));

                // eliminam valoarea minima din coada cu prioritate daca sunt M+1 elemente in coada
                if (pq.size() > M)
                {
                    pq.delMin();
                }
            } // cele mai mari M elemente sunt in coada



            // afisam elementele din coada cu prioritate in ordine inversa
            Stack <int> stack = new Stack <int>();

            foreach (var item in pq)
            {
                stack.push(item);
            }

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
        }