PushFront() public method

public PushFront ( element ) : void
return void
Ejemplo n.º 1
0
 public void Clear()
 {
     _buffer.PushBack(1);
     _buffer.PushFront(1);
     Assert.That(_buffer.Count, Is.EqualTo(2));
     _buffer.Clear();
     Assert.That(_buffer.Count, Is.EqualTo(0));
 }
Ejemplo n.º 2
0
            public Test FrontPushesItemsAtFront()
            {
                deque.PushFront("extern");
                deque.PushFront("void");
                deque.PushFront("stackalloc");

                return(Assert.That(deque.Take(3)).Is.SequenceEqualTo("stackalloc", "void", "extern"));
            }
Ejemplo n.º 3
0
        public void ReleasedAfterPushFront()
        {
            Deque dq = new Deque();

            Assert.IsTrue(dq.MutexAvailable());
            dq.PushFront("abc");
            Assert.IsTrue(dq.MutexAvailable());
            dq.PushFront("def");
            Assert.IsTrue(dq.MutexAvailable());
        }
Ejemplo n.º 4
0
        public void TestPeekFrontBack()
        {
            var deque = new Deque <int>();

            deque.PushFront(1);
            deque.PushFront(2);
            Assert.AreEqual(2, deque.PeekFront());
            Assert.AreEqual(1, deque.PeekBack());
            Assert.AreEqual(2, deque.Count);
        }
Ejemplo n.º 5
0
        public void Resize(uint Size)
        {
            //m_Cache.Resize(Size, uint.MaxValue);

            m_Cache.Clear();
            for (int x = 0; x < Size; x++)
            {
                m_Cache.PushFront(uint.MaxValue);
            }
        }
Ejemplo n.º 6
0
        public void TestPushPopFront()
        {
            var deque = new Deque <int>();

            deque.PushFront(1);
            deque.PushFront(2);
            deque.PushFront(3);
            Assert.AreEqual(3, deque.PopFront());
            Assert.AreEqual(2, deque.PopFront());
            Assert.AreEqual(1, deque.PopFront());
            Assert.AreEqual(0, deque.Count);
        }
Ejemplo n.º 7
0
    public static void Main()
    {
        var s = Console.ReadLine();
        var q = int.Parse(Console.ReadLine());

        Deque <char> deque = new Deque <char>();

        foreach (var c in s)
        {
            deque.PushBack(c);
        }
        int front = 0;

        for (int i = 0; i < q; i++)
        {
            var query = Console.ReadLine();
            if (query == "1")
            {
                front ^= 1;
            }
            else
            {
                if (query[2] == '1' ^ front == 0)
                {
                    deque.PushBack(query[4]);
                }
                else
                {
                    deque.PushFront(query[4]);
                }
            }
        }

        Console.WriteLine(string.Join("", front == 0 ? deque : deque.Reverse()));
    }
Ejemplo n.º 8
0
 private static void FrontPushAll(Deque <string> deque, params string[] items)
 {
     foreach (string item in items)
     {
         deque.PushFront(item);
     }
 }
Ejemplo n.º 9
0
        public void EnumerateDeque_Invalidation_PushFront()
        {
            List <int> coll = new List <int>()
            {
                4, 5, 8, 10, 2
            };
            Deque <int> deque = new Deque <int>(coll);           //tests add

            int index = 0;

            try
            {
                foreach (int num in deque)
                {
                    deque.PushFront(4);
                    Assert.AreEqual(num, coll[index]);
                    ++index;
                }

                Assert.Fail();
            }
            catch (InvalidOperationException)
            {
            }
        }
Ejemplo n.º 10
0
 public override void PushFront(T item)
 {
     lock (root)
     {
         deque.PushFront(item);
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Executes the delegate on the main thread that this object executes on.
        /// </summary>
        /// <param name="method">
        /// A Delegate to a method that takes parameters of the same number and
        /// type that are contained in args.
        /// </param>
        /// <param name="args">
        /// An array of type Object to pass as arguments to the given method.
        /// </param>
        /// <returns>
        /// An IAsyncResult interface that represents the asynchronous operation
        /// started by calling this method.
        /// </returns>
        /// <remarks>
        /// The delegate is placed at the beginning of the queue. Its invocation
        /// takes priority over delegates already in the queue.
        /// </remarks>
        public IAsyncResult BeginInvokePriority(Delegate method, params object[] args)
        {
            #region Require

            if (disposed)
            {
                throw new ObjectDisposedException("DelegateQueue");
            }
            else if (method == null)
            {
                throw new ArgumentNullException();
            }

            #endregion

            DelegateQueueAsyncResult result;

            // If BeginInvokePriority was called from a different thread than the one
            // in which the DelegateQueue is running.
            if (InvokeRequired)
            {
                result = new DelegateQueueAsyncResult(this, method, args, false, NotificationType.BeginInvokeCompleted);

                lock (lockObject)
                {
                    // Put the method at the front of the queue.
                    delegateDeque.PushFront(result);

                    Monitor.Pulse(lockObject);
                }
            }
            // Else BeginInvokePriority was called from the same thread in which the
            // DelegateQueue is running.
            else
            {
                result = new DelegateQueueAsyncResult(this, method, args, true, NotificationType.None);

                // The method is invoked here instead of placing it in the
                // queue. The reason for this is that if EndInvoke is called
                // from the same thread in which the DelegateQueue is running and
                // the method has not been invoked, deadlock will occur.
                result.Invoke();
            }

            return(result);
        }
Ejemplo n.º 12
0
    void Solve()
    {
        var K  = F();
        var es = new List <E> [K];

        for (var i = 0; i < K; i++)
        {
            es[i] = new List <E> {
                new E((i + 1) % K, true), new E((i * 10) % K, false)
            }
        }
        ;
        var d = new int[K];

        for (var i = 0; i < K; i++)
        {
            d[i] = MOD;
        }
        d[1] = 0;
        var deq = new Deque <int>();

        deq.PushFront(1);
        while (deq.Count > 0)
        {
            var u = deq.PopFront();
            foreach (var t in es[u])
            {
                int v = t.T, cost = t.IsHeavy ? 1 : 0, tmp = d[u] + cost;
                if (d[v] > tmp)
                {
                    d[v] = tmp;
                    if (t.IsHeavy)
                    {
                        deq.PushBack(v);
                    }
                    else
                    {
                        deq.PushFront(v);
                    }
                }
            }
        }
        Console.WriteLine(d[0] + 1);
    }
}
Ejemplo n.º 13
0
 /// <summary>
 /// Puts a path renderer at the front of the list. Evicts the back of the list if at capacity.
 /// </summary>
 /// <param name="pathRenderer">The path renderer to put at the front of the list.</param>
 private void PushFront(PathRenderer pathRenderer)
 {
     if (pathList.Count >= CAPACITY)
     {
         pathList.PopBack().SetVisible(false);
     }
     pathList.PushFront(pathRenderer);
     pathRenderer.SetVisible(outlinePath);
 }
Ejemplo n.º 14
0
        public void PushFrontTest()
        {
            var list  = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
            var deque = new Deque <int>(list);

            deque.PushFront(9);
            Assert.AreEqual(10, deque.Count);
            Assert.AreEqual(18, deque.Capacity);
            Assert.AreEqual(9, deque[0]);
        }
Ejemplo n.º 15
0
        void Init(int selectedNote)
        {
            if (selectedNote < 0)
            {
                selectedNote = lastNoteSelected;
            }

            gameObject.SetActive(true);

            selectedKey      = keyPool.GetObject(selectedTransform.position, selectedTransform.rotation).GetComponent <Key>();
            selectedKey.Note = selectedNote;
            selectedKey.transform.SetParent(transform);
            keys.PushFront(selectedKey);

            InitHalfKeyboard(1);
            InitHalfKeyboard(-1);

            selectedKeyOffset = 0;

            maxKeyPositionY      = NoteToKeyPosition(127);
            selectedKeyPositionY = NoteToKeyPosition(selectedNote);
        }
Ejemplo n.º 16
0
        public void TestPushFrontOnEmpty()
        {
            //arrange
            Deque dq = new Deque();

            //act
            dq.PushFront("abcd");

            //assert
            Assert.AreSame(dq.head, dq.tail);
            Assert.IsNotNull(dq.head);
            Assert.AreEqual(dq.head.data, "abcd");
        }
Ejemplo n.º 17
0
        // Use this for initialization
        void Awake()
        {
            testDeque = new Deque <int>(N);

            //Test push, pop, and get when initial size is not exceeded
            testDeque.PushFront(1);
            testDeque.PushBack(-1);
            testDeque.PushFront(2);
            testDeque.PushFront(-2);
            testDeque.PushFront(3);

            Debug.Assert(testDeque.Get(0) == 3);
            Debug.Assert(testDeque.Get(1) == -2);
            Debug.Assert(testDeque.Get(2) == 2);
            Debug.Assert(testDeque.Get(3) == 1);
            Debug.Assert(testDeque.Get(4) == -1);

            Debug.Assert(testDeque.PopFront() == 3);
            Debug.Assert(testDeque.PopBack() == -1);
            Debug.Assert(testDeque.PopBack() == 1);
            Debug.Assert(testDeque.PopBack() == 2);
            Debug.Assert(testDeque.PopFront() == -2);
        }
Ejemplo n.º 18
0
        public void AddValue(float value)
        {
            while (_buffer.Count != 0 && _buffer.Front.value <= value)
            {
                _buffer.PopFront();
            }

            _buffer.PushFront(new IndexValuePair(_count, value));
            _count++;

            while (_buffer.Back.index < (_count - _history))
            {
                _buffer.PopBack();
            }
        }
Ejemplo n.º 19
0
        public void TestOtherQueueOrder()
        {
            // queue-like ordering (FIFO) can also be achieved using push_front and pop_back
            Deque dq = new Deque();

            for (int i = 0; i < 10; i++)
            {
                dq.PushFront(i);
            }

            for (int i = 0; i < 10; i++)
            {
                int j = (int)dq.PopBack();
                Assert.AreEqual(i, j);
            }
        }
Ejemplo n.º 20
0
        public void TestStackOrder()
        {
            // stack-like (LIFO) ordering is achieved using push_front and pop
            Deque dq = new Deque();

            for (int i = 0; i < 10; i++)
            {
                dq.PushFront(i);
            }

            for (int i = 9; i >= 0; i--)
            {
                int j = (int)dq.Pop();
                Assert.AreEqual(i, j);
            }
        }
Ejemplo n.º 21
0
 public override void ActionRejected(Query query)
 {
     switch (query)
     {
     case Query.Move:
         var target = Position + GameState.ConvertDirectionToSize[Direction];
         if (!MapManager.InBounds(target))
         {
             return;
         }
         if (MapManager.Map[target.X, target.Y].ObjectContainer.ShowDecor() is ClosedDoor)
         {
             actionQueue.PushFront(Query.Interaction);
         }
         break;
     }
 }
Ejemplo n.º 22
0
        private static void PopulateDequePushFront(Deque deque)
        {
            deque.Clear();

            for (int i = 0; i < ElementCount; i++)
            {
                deque.PushFront(i);
            }

            Debug.Assert(deque.Count == ElementCount);

            int j = ElementCount - 1;

            foreach (int i in deque)
            {
                Debug.Assert(i == j);
                j--;
            }
        }
        private static void PopulateDequePushFront(Deque deque)
        {
            deque.Clear();

            for(int i = 0; i < ElementCount; i++)
            {
                deque.PushFront(i);
            }

            System.Diagnostics.Debug.Assert(deque.Count == ElementCount);

            int j = ElementCount - 1;

            foreach(int i in deque)
            {
                System.Diagnostics.Debug.Assert(i == j);
                j--;
            }
        }
Ejemplo n.º 24
0
        public void Solve()
        {
            var    n   = ri;
            var    L   = rl;
            var    deq = new Deque <X>();
            double sum = 0;

            for (int _ = 0; _ < n; _++)
            {
                var x = new X(ri, ri);
                sum += x.temp * x.vol;
                if (deq.Count == 0)
                {
                    deq.PushBack(x);
                }
                else
                {
                    //???????
                    {
                        var v = x.vol;
                        while (v > 0)
                        {
                            var p  = deq.PopFront(); sum -= p.temp * p.vol;
                            var mi = Math.Min(v, p.vol);
                            p.vol -= mi; v -= mi;
                            if (p.vol > 0)
                            {
                                deq.PushFront(p); sum += p.temp * p.vol;
                            }
                        }
                    }
                    while (deq.Count > 0 && deq[deq.Count - 1].temp >= x.temp)
                    {
                        var p  = deq.PopBack();
                        var nv = x.vol + p.vol;
                        x = new X((x.temp * x.vol + p.temp * p.vol) / nv, nv);
                    }
                    deq.PushBack(x);
                }
                Console.WriteLine("{0:0.000000000000}", 1.0 * sum / L);
            }
        }
Ejemplo n.º 25
0
    int BFS01(int S, int T, List <Edge>[] E)
    {
        var deq     = new Deque <long>();
        int N       = E.Length;
        var minCost = new int[N];

        for (int i = 0; i < N; i++)
        {
            minCost[i] = INF;
        }
        minCost[S] = 0;
        deq.PushBack((long)S << 32);
        while (deq.Count > 0)
        {
            long mask = deq.PopFront();
            int  a = (int)(mask >> 32), cost = (int)mask;
            if (cost > minCost[a])
            {
                continue;
            }
            if (a == T)
            {
                return(cost);
            }
            foreach (var e in E[a])
            {
                if (minCost[e.to] == INF)
                {
                    minCost[e.to] = minCost[a] + e.cost;
                    if (e.cost == 0)
                    {
                        deq.PushFront(((long)e.to << 32) + minCost[a]);
                    }
                    else
                    {
                        deq.PushBack(((long)e.to << 32) + minCost[a] + 1);
                    }
                }
            }
        }
        return(INF);
    }
Ejemplo n.º 26
0
    public void Solve()
    {
        Scan();
        var ans = new int[K];
        var q   = new Deque <S>();

        q.PushBack(new S(1, 1));
        while (q.Count > 0)
        {
            var t = q.PopBack();
            if (ans[t.Num] != 0)
            {
                continue;
            }
            ans[t.Num] = t.Sum;
            q.PushBack(new S((t.Num * 10) % K, t.Sum));
            q.PushFront(new S((t.Num + 1) % K, t.Sum + 1));
        }
        Console.WriteLine(ans[0]);
    }
Ejemplo n.º 27
0
    public static void Main()
    {
        int         n     = int.Parse(Console.ReadLine());
        var         a     = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Deque <int> deque = new Deque <int>();

        for (int i = 0; i < a.Length; i++)
        {
            if (((i ^ n) & 1) == 0)
            {
                deque.PushBack(a[i]);
            }
            else
            {
                deque.PushFront(a[i]);
            }
        }

        Console.WriteLine(string.Join(" ", deque));
    }
Ejemplo n.º 28
0
        public static void Solve()
        {
            var N   = Scanner.Scan <int>();
            var S   = Scanner.ScanLine();
            var deq = new Deque <int>();

            deq.PushBack(N);
            foreach (var(c, i) in S.Select((x, i) => (x, i)).Reverse())
            {
                if (c == 'L')
                {
                    deq.PushBack(i);
                }
                else
                {
                    deq.PushFront(i);
                }
            }

            Console.WriteLine(string.Join(" ", deq));
        }
Ejemplo n.º 29
0
        public void Deque_Add_FrontExtension()
        {
            List <int> coll = new List <int>()
            {
                4, 5, 8, 10, 2, 5, 6, 7
            };
            Deque <int> deque = new Deque <int>(coll);           //tests add

            coll.Insert(0, 5);
            deque.PushFront(5);

            Assert.AreEqual(coll.Count, deque.Count);


            int index = 0;

            foreach (int a in deque)
            {
                Assert.AreEqual(coll[index], a);
                ++index;
            }
        }
Ejemplo n.º 30
0
        public void Deque_ExtendRight_thenLeft()
        {
            List <int>  coll  = new List <int>();
            Deque <int> deque = new Deque <int>();       //tests add

            for (int i = 0; i < 3 * 56; i++)             //see default sizes; might have changed
            {
                coll.Add(i);
                deque.Add(i);
            }

            deque.PushFront(50);
            coll.Insert(0, 50);

            int index = 0;

            foreach (int a in deque)
            {
                Assert.AreEqual(coll[index], a);
                ++index;
            }
        }
Ejemplo n.º 31
0
    public static void Main()
    {
        string       s        = Console.ReadLine();
        bool         reversed = false;
        Deque <char> deq      = new Deque <char>();

        foreach (var c in s)
        {
            if (c == 'R')
            {
                reversed = !reversed;
            }
            else
            {
                if (reversed)
                {
                    deq.PushFront(c);
                }
                else
                {
                    deq.PushBack(c);
                }
            }
        }
        Stack <char> res = new Stack <char>();

        foreach (var item in reversed ? deq.Reverse() : deq)
        {
            if (res.Any() && item == res.Peek())
            {
                res.Pop();
            }
            else
            {
                res.Push(item);
            }
        }
        Console.WriteLine(res.Reverse().ToArray());
    }