System.Collections.Queue.Enqueue C# (CSharp) Method

Enqueue() public method

public Enqueue ( Object obj ) : void
obj Object
return void
        public virtual void Enqueue(Object obj)
        {
            if (_size == _array.Length)
            {
                int newcapacity = (int)((long)_array.Length * (long)_growFactor / 100);
                if (newcapacity < _array.Length + _MinimumGrow)
                {
                    newcapacity = _array.Length + _MinimumGrow;
                }
                SetCapacity(newcapacity);
            }

            _array[_tail] = obj;
            _tail = (_tail + 1) % _array.Length;
            _size++;
            _version++;
        }

Same methods

Queue::Enqueue ( object obj ) : void

Usage Example

Ejemplo n.º 1
1
        private static void FillQueue(int firstX, int firstY, byte currColor, byte destColor)
        {
            Queue<Tuple<int, int>> q = new Queue<Tuple<int, int>>();
            q.Enqueue(Tuple.Create(firstX, firstY));

            var maxX = _data.GetLength(0);
                var maxY = _data.GetLength(1);
            while (q.Count > 0)
            {
                var point = q.Dequeue();
                var x = point.Item1;
                var y = point.Item2;

                if (_data[x, y] == destColor)
                    continue;
                if (_data[x, y] != currColor)
                    continue;

                _data[x, y] = destColor;

                if (x + 1 < maxX)
                    q.Enqueue(Tuple.Create(x + 1, y));
                if (x - 1 >= 0)
                    q.Enqueue(Tuple.Create(x - 1, y));

                if (y + 1 < maxY)
                    q.Enqueue(Tuple.Create(x, y + 1));
                if (y - 1 >= 0)
                    q.Enqueue(Tuple.Create(x, y - 1));

                Display(_data);
            }
        }
All Usage Examples Of System.Collections.Queue::Enqueue