예제 #1
0
 // add all items to copy of heap
 // takes linear time since already in heap order so no Keys move
 public HeapIndexMinPQEnumerator(int n, int[] pq, T[] keys)
 {
     _copy = new IndexMinPQ <T>(pq.Length - 1);
     for (var i = 1; i <= n; i++)
     {
         _copy.Insert(pq[i], keys[pq[i]]);
     }
 }
예제 #2
0
        private void InsertWords(IEnumerable <string> list)
        {
            foreach (var word in list)
            {
                var indexEmpty = 0;

                for (var i = 0; i < _n; i++)
                {
                    if (!_pq.Contains(i))
                    {
                        indexEmpty = i;
                        break;
                    }
                }

                _pq.Insert(indexEmpty, word);
                if (_pq.Size() == _n)
                {
                    _pq.DelMin();
                }
            }
        }