/// <summary> /// 获取堆的迭代器,元素以升序排列。 /// </summary> /// <returns></returns> public IEnumerator <Key> GetEnumerator() { MinPQ <Key> copy = new MinPQ <Key>(this.n); for (int i = 1; i <= this.n; i++) { copy.Insert(this.pq[i]); } while (!copy.IsEmpty()) { yield return(copy.DelMin()); // 下次迭代的时候从这里继续执行。 } }
/// <summary> /// 获取堆的迭代器,元素以升序排列。 /// </summary> /// <returns></returns> public IEnumerator <Key> GetEnumerator() { var copy = new MinPQ <Key>(n); for (var i = 1; i <= n; i++) { copy.Insert(pq[i]); } while (!copy.IsEmpty()) { yield return(copy.DelMin()); // 下次迭代的时候从这里继续执行。 } }