예제 #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);
        }