Exemplo n.º 1
0
        /// <summary>
        /// 获取迭代器。
        /// </summary>
        /// <returns>最大堆的迭代器。</returns>
        public IEnumerator <int> GetEnumerator()
        {
            var copy = new IndexMaxPQ <Key>(n);

            for (var i = 0; i < n; i++)
            {
                copy.Insert(keys[pq[i]], pq[i]);
            }

            while (!copy.IsEmpty())
            {
                yield return(copy.DelMax());
            }
        }
        /// <summary>
        /// 获取迭代器。
        /// </summary>
        /// <returns></returns>
        public IEnumerator <int> GetEnumerator()
        {
            IndexMaxPQ <Key> copy = new IndexMaxPQ <Key>(this.n);

            for (int i = 0; i < this.n; i++)
            {
                copy.Insert(this.keys[this.pq[i]], this.pq[i]);
            }

            while (!copy.IsEmpty())
            {
                yield return(copy.DelMax());
            }
        }