Exemplo n.º 1
0
        public void Enqueue(T val, int prior)
        {
            //increase size

            /*
             * if (Count >= Capacity)
             * {
             *  Capacity *= 2;
             *  PNode<T>[] temp = new PNode<T>[Capacity];
             *
             *  for (int i = 0; i < PriorityList.Length; i++)
             *  {
             *      temp[i] = PriorityList[i];
             *  }
             *
             *
             *  PriorityList = temp;
             * }
             */
            if (Count >= Capacity)
            {
                Capacity *= 2;
                PNode <T>[] temp = new PNode <T> [Capacity];

                for (int i = 0; i < PriorityList.Length; i++)
                {
                    temp[i] = PriorityList[i];
                }
            }

            for (int i = 0; i < PriorityList.Length; i++)
            {
                if (PriorityList[i] == null)
                {
                    PriorityList[i] = new PNode <T>(val, prior);
                    break;
                }
            }


            Count++;
            Sort();
            /// calls below class
        }
Exemplo n.º 2
0
        public PNode <T> Dequeue()
        {
            if (Count == 0)
            {
                throw new InvalidOperationException("queue empty");
            }

            PNode <T> val = null;

            for (int i = 0; i < PriorityList.Length; i++)
            {
                if (PriorityList[i] != null)
                {
                    val             = PriorityList[i];
                    PriorityList[i] = null;

                    break;
                }
            }
            Count--;
            return(val);
        }