Beispiel #1
0
 /// <summary>
 /// Method, which delete the first element with the highest priority of the queue and returns its value
 /// </summary>
 /// <returns>value element</returns>
 public int Dequeue()
 {
     if (head == null)
     {
         throw new EmptyQueueException("Empty Queue");
     }
     QueueElement tmp = head;
     if (tmp.Priority == queueMaxPriority)
     {
         head = head.Next;
         return tmp.Element;
     }
     else
     {
         tmp = tmp.Next;
         QueueElement previousElement = head;
         while (tmp.Priority != queueMaxPriority)
         {
             previousElement = tmp;
             tmp = tmp.Next;
         }
         previousElement.Next = tmp.Next;
         return tmp.Element;
     }
 }
Beispiel #2
0
 /// <summary>
 /// Method, which add a new element with its priority.
 /// </summary>
 /// <param name="value">value of the element</param>
 /// <param name="priority">priority of the element</param>
 public void Enqueue(int value, int priority)
 {
     if (tail == null)
     {
         QueueElement tmp = new QueueElement(null, value, priority);
         head = tmp;
         tail = tmp;
         queueMaxPriority = tmp.Priority;
     }
     else
     {
         QueueElement tmp = new QueueElement(null, value, priority);
         tail.Next = tmp;
         tail = tmp;
         if (queueMaxPriority < tmp.Priority)
         {
             queueMaxPriority = tmp.Priority;
         }
     }
 }
Beispiel #3
0
 public QueueElement(QueueElement next, int value, int priority)
 {
     this.Element = value;
     this.Priority = priority;
     this.Next = next;
 }