public void Enqueue(T value, int priority = int.MinValue)
        {
            if (!_priorityMap.ContainsKey(priority))
            {
                _priorityMap.Add(priority, new Queue <T>());
                _heap.Push(priority);
            }

            _priorityMap[priority].Enqueue(value);
            Count++;
        }
        public PriorityQueue(IEnumerable <IEnumerable <T> > values, int startingPriority = int.MaxValue)
        {
            _heap        = new MaxHeap <int>();
            _priorityMap = new Dictionary <int, Queue <T> >();
            Count        = 0;

            if (values == null)
            {
                return;
            }

            int priorityCount = values.Count();

            if (priorityCount == 0)
            {
                return;
            }

            if ((startingPriority - int.MinValue) < priorityCount)
            {
                throw new ArgumentException("There are not enough priorities to cover number of collections given.");
            }

            foreach (var p in values)
            {
                if (p.Count() > 0)
                {
                    _heap.Push(startingPriority);
                    _priorityMap.Add(startingPriority, new Queue <T>());

                    foreach (var v in p)
                    {
                        _priorityMap[startingPriority].Enqueue(v);
                    }
                }

                startingPriority--;
            }
        }
Exemple #3
0
 private static void AddNewCookie(int iMixedCookieSweetness)
 {
     _heap.Push(iMixedCookieSweetness);
 }