Beispiel #1
0
 public ArrayQueue(ArrayQueue <T> other)
 {
     arr      = new List <T>(other.arr);
     start    = other.start;
     num      = other.num;
     capacity = other.capacity;
 }
Beispiel #2
0
        private void expand()
        {
            // expand array queue.
            ArrayQueue <T> temp = new ArrayQueue <T>(capacity * 2);

            //
            for (int i = 0; i < capacity; ++i)
            {
                temp.set(i, arr[(start + i) & (capacity - 1)]);
            }
            temp.start    = 0;
            temp.num      = size();
            this.num      = temp.num;
            this.arr      = temp.arr;
            this.start    = temp.start;
            this.capacity = temp.capacity;
        }
Beispiel #3
0
        public void push(ArrayQueue <T> other) // chk!!
        {
            if (other.empty())
            {
                return;
            }
            int newSize = capacity;

            while (newSize - num < other.size())
            {
                newSize = newSize * 2;
            }
            if (newSize != this.capacity)
            {
                // expand array queue.
                ArrayQueue <T> temp = new ArrayQueue <T>(newSize);
                temp.start = 0;
                //
                for (int i = 0; i < this.size(); ++i)
                {
                    temp.set(i, this.get(i));
                }

                int iend = other.num;
                for (int i = 0; i < iend; ++i)
                {
                    temp.set(i + this.num, other.get(i));
                }

                temp.num      = this.num + other.num;
                this.arr      = temp.arr;
                this.num      = temp.num;
                this.start    = temp.start;
                this.capacity = temp.capacity;
            }
            else
            {
                for (int i = 0; i < other.size(); ++i)
                {
                    this.push((other.get(i)));
                }
            }
        }