コード例 #1
0
            public bool MoveNext()
            {
                if (!copy.IsEmpty())
                {
                    Current = copy.DelMin();
                    return(true);
                }

                return(false);
            }
コード例 #2
0
        public static void Main(string[] args)
        {
            // insert a bunch of strings
            string[] strings = { "it", "was", "the", "best", "of", "times", "it", "was", "the", "worst" };

            var pq = new IndexMinPQ <string>(strings.Length);

            for (int i = 0; i < strings.Length; i++)
            {
                pq.Insert(i, strings[i]);
            }

            // delete and print each key
            while (!pq.IsEmpty())
            {
                int i = pq.DelMin();
                Console.WriteLine(i + " " + strings[i]);
            }
            Console.WriteLine();

            // reinsert the same strings
            for (int i = 0; i < strings.Length; i++)
            {
                pq.Insert(i, strings[i]);
            }

            // print each key using the iterator
            foreach (int i in pq)
            {
                Console.WriteLine(i + " " + strings[i]);
            }

            while (!pq.IsEmpty())
            {
                pq.DelMin();
            }
        }