Пример #1
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="AlternativePriorityQueue{TPriority, TData}"/> class.
        /// </summary>
        /// <param name="copyFrom">
        /// The <see cref="AlternativePriorityQueue{TPriority, TData}"/> to
        /// copy from.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="copyFrom"/> is <see langword="null"/>.
        /// </exception>
        public AlternativePriorityQueue(AlternativePriorityQueue <TPriority, TData> copyFrom)
        {
            if (copyFrom == null)
            {
                throw new ArgumentNullException("copyFrom");
            }

            this.nodes            = new List <PriorityQueueNode <TPriority, TData> >(copyFrom.nodes.Count);
            this.priorityComparer = copyFrom.priorityComparer;

            // We need to copy the nodes, because they store queue state that
            // will change in one queue but not in the other.
            for (int i = 0; i < copyFrom.nodes.Count; i++)
            {
                var nodeToCopy = copyFrom.nodes[i];
                var copiedNode = nodeToCopy == null
                    ? null
                    : new PriorityQueueNode <TPriority, TData>(nodeToCopy);
                this.nodes.Add(copiedNode);
            }
        }
Пример #2
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 /// <param name="capacity">The capacity of the queue</param>
 /// <param name="comparer">The comparer to use for computing priority values</param>
 public PriorityQueue(int capacity, IComparer <T> comparer)
 {
     _queue = new AlternativePriorityQueue <T, T>(capacity, comparer);
 }
Пример #3
0
 /// <summary>
 /// Creates an instance of this class
 /// </summary>
 public PriorityQueue()
 {
     _queue = new AlternativePriorityQueue <T, T>();
 }