Пример #1
0
        public static void Test()
        {
            QueueArray array = new QueueArray();

            array.QueusImplementByArray(8);
            ArrayModel item1 = new ArrayModel()
            {
                id   = 1,
                name = "A"
            };

            array.Enqueue(item1);
            ArrayModel item2 = new ArrayModel()
            {
                id   = 2,
                name = "D"
            };

            array.Enqueue(item2);
            ArrayModel item3 = new ArrayModel()
            {
                id   = 3,
                name = "W"
            };

            array.Enqueue(item3);
            var temp1 = array.Dequeue();
            var temp2 = array.Dequeue();
            var temp3 = array.Dequeue();
        }
Пример #2
0
 public void Push(ArrayModel item)
 {
     if (array.Length == number)
     {
         Resize(2 * array.Length);
     }
     array[number++] = item;
 }
Пример #3
0
 public void Enqueue(ArrayModel _item)
 {
     if ((head - tail + 1) == array.Length)
     {
         Resize(2 * array.Length);
     }
     array[tail++] = _item;
 }
Пример #4
0
 private void Resize(int capacity)
 {
     ArrayModel[] temp = new ArrayModel[capacity];
     for (var i = 0; i < (capacity > array.Length ? array.Length : capacity); i++)
     {
         temp[i] = array[i];
     }
     array = temp;
 }
Пример #5
0
        public ArrayModel Pop()
        {
            ArrayModel temp = array[--number];

            array[number] = default(ArrayModel);
            if (number > 0 && number == array.Length / 4)
            {
                Resize(array.Length / 2);
            }
            return(temp);
        }
Пример #6
0
        private void Resize(int capacity)
        {
            ArrayModel[] temp  = new ArrayModel[capacity];
            int          index = 0;

            for (int i = head; i < (capacity > array.Length ? array.Length : capacity); i++)
            {
                temp[index++] = array[i];
            }
            array = temp;
        }
Пример #7
0
        public ArrayModel Dequeue()
        {
            ArrayModel temp = array[head];

            array[head] = default(ArrayModel);
            if (head > 0 && (tail - head + 1) == array.Length / 4)
            {
                Resize(array.Length / 2);
            }
            head++;
            return(temp);
        }