Exemplo n.º 1
0
 /// Adds QueueElement according to its priority.
 public void enqueue(QueueElement added)
 {
     OverloadCheck();
     int i = 0;
     for (i = 0; i < size && list[i].Priority < added.Priority; ++i);
     for (int j = size - 1; j >= i; j--)
     {
         list[j + 1] = list[j];
     }
     list[i] = added;
     size++;
 }
Exemplo n.º 2
0
        /// Adds QueueElement according to its priority.
        public void enqueue(QueueElement added)
        {
            OverloadCheck();
            int i = 0;

            for (i = 0; i < size && list[i].Priority < added.Priority; ++i)
            {
                ;
            }
            for (int j = size - 1; j >= i; j--)
            {
                list[j + 1] = list[j];
            }
            list[i] = added;
            size++;
        }
Exemplo n.º 3
0
        /// <summary>
        /// add element with priority
        /// </summary>
        /// <param name="value"></param>
        /// <param name="prior"></param>
        public void Enqueue(T value, int prior)
        {
            QueueElement temp       = head;
            QueueElement newElement = new QueueElement(value, prior);

            newElement.Next = temp;
            newElement.Back = null;
            head            = newElement;
            if (size != 0)
            {
                temp.Back = head;
            }
            size++;
            if (newElement.Priority > max)
            {
                max = newElement.Priority;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns element with biggest priority, which was first added
        /// </summary>
        /// <returns></returns>
        public T Dequeue()
        {
            if (IsEmpty())
            {
                throw new Exception();
            }
            else
            {
                var temp     = head;
                var toReturn = head;
                while (temp.Next != null)
                {
                    if (temp.Priority == max)
                    {
                        toReturn = temp;
                    }
                    temp = temp.Next;
                }

                var check = toReturn.Value;

                if (toReturn == head)
                {
                    head = toReturn.Next;
                    size--;
                    NewMax();
                    return(check);
                }
                if (toReturn.Next == null)
                {
                    temp.Back.Next = null;
                    size--;
                    NewMax();
                    return(check);
                }
                toReturn.Back.Next = toReturn.Next;
                toReturn.Next.Back = toReturn.Back;
                size--;
                NewMax();
                return(check);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Конструктор очереди, принимающий данные и приоритет превого элемента
 /// </summary>
 public Queue(T data, int priority)
 {
     QueueElements    = new QueueElement <T> [1];
     QueueElements[0] = new QueueElement <T>(data, priority);
 }