当前位置: 首页>>代码示例>>C#>>正文


C# Deque.RemoveFront方法代码示例

本文整理汇总了C#中Deque.RemoveFront方法的典型用法代码示例。如果您正苦于以下问题:C# Deque.RemoveFront方法的具体用法?C# Deque.RemoveFront怎么用?C# Deque.RemoveFront使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Deque的用法示例。


在下文中一共展示了Deque.RemoveFront方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestAdd

        public void TestAdd()
        {
            Deque<int> deque = new Deque<int>();

            Assert.IsTrue(deque.IsEmpty);

            int item = 1;

            Assert.IsFalse(deque.Contains(item));
            deque.Add(item);

            int actualBack;
            actualBack = deque[0];

            Assert.IsTrue(deque.Contains(item));
            Assert.AreEqual(item, actualBack);

            int itemNewBack = 2;
            Assert.IsFalse(deque.Contains(itemNewBack));
            deque.AddBack(itemNewBack);

            Assert.IsTrue(deque.Contains(itemNewBack));
            actualBack = deque[1];
            Assert.AreEqual(itemNewBack, actualBack);

            actualBack = deque.RemoveBack();
            Assert.AreEqual(itemNewBack, actualBack);

            int itemNewFront = -1;
            Assert.IsFalse(deque.Contains(itemNewFront));
            deque.AddFront(itemNewFront);

            int actualFront;
            Assert.IsTrue(deque.Contains(itemNewFront));

            actualFront = deque[0];
            Assert.AreEqual(itemNewFront, actualFront);

            actualFront = deque.RemoveFront();
            Assert.AreEqual(itemNewFront, actualFront);

            int[] itemRange = new[] { 3, 4, 5, 6 };
            int offset = deque.Count;
            deque.AddRange(itemRange);

            foreach (var itm in itemRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemBackRange = new[] { 7, 8, 9, 10 };
            offset = deque.Count;
            deque.AddBackRange(itemBackRange);
            foreach (var itm in itemBackRange)
            {
                Assert.AreEqual(itm, deque[offset]);
                offset++;
            }

            int[] itemFrontRange = new[] { 3, 4, 5, 6 };
            deque.AddFrontRange(itemFrontRange);

            for (int i = 0; i < itemFrontRange.Length; i++)
            {
                var itm = itemFrontRange[i];
                Assert.AreEqual(itm, deque[i]);
            }
        }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:69,代码来源:DequeTests.cs

示例2: TestRemove

        public void TestRemove()
        {
            int[] items = new[] { 0, 1, 2, 3 };
            Deque<int> deque = new Deque<int>(items);

            Assert.IsTrue(deque.Contains(0));
            Assert.IsTrue(deque.Remove(0));
            Assert.IsFalse(deque.Contains(0));
            Assert.AreEqual(1, deque.RemoveFront());
            Assert.AreEqual(3, deque.RemoveBack());

            deque.Clear();
            deque.AddRange(items);
            Assert.IsTrue(deque.Contains(2));
            deque.RemoveAt(2);
            Assert.IsFalse(deque.Contains(2));

            deque.Clear();
            deque.AddRange(items);

            foreach (var item in items)
            {
                Assert.IsTrue(deque.Contains(item));
            }

            deque.RemoveRange(1, 2);

            Assert.IsTrue(deque.Contains(0));
            Assert.IsFalse(deque.Contains(1));
            Assert.IsFalse(deque.Contains(2));
            Assert.IsTrue(deque.Contains(3));
        }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:32,代码来源:DequeTests.cs

示例3: TestAddVariants

 public void TestAddVariants()
 {
     for (int i = 0; i < Math.Pow(2, 4); i++)
     {
         Deque<int> deque = new Deque<int>();
         if (back(i, 0))
         {
             deque.AddBack(1);
         }
         else
         {
             deque.AddFront(1);
         }
         if (back(i, 1))
         {
             deque.RemoveBack();
         }
         else
         {
             deque.RemoveFront();
         }
         if (back(i, 2))
         {
             deque.AddBack(2);
         }
         else
         {
             deque.AddFront(2);
         }
         int item;
         if (back(i, 3))
         {
             item = deque.RemoveBack();
         }
         else
         {
             item = deque.RemoveFront();
         }
         Assert.AreEqual(2, item);
     }
 }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:41,代码来源:DequeTests.cs

示例4: TestBulkInsert

        public void TestBulkInsert()
        {
            int loops = 100000;
            Deque<int> deque = new Deque<int>();

            deque.AddFront(loops - 1);
            for (int i = 0; i < loops - 1; i++)
            {
                deque.Insert(deque.Count-1, i);
            }

            Deque<int> dequeCopy = new Deque<int>(deque);

            for (int expected = 0; expected < loops; expected++)
            {
                int actual = deque.RemoveFront();
                int actualCopy = dequeCopy[expected];

                Assert.AreEqual(expected, actual, "Original deque item differs from expected value");
                Assert.AreEqual(expected, actualCopy, "Copied deque item differs from expected value");
            }
        }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:22,代码来源:DequeTests.cs

示例5: TestAddBack

 public void TestAddBack()
 {
     Deque<int> deque = new Deque<int>();
     deque.AddBack(1);
     deque.RemoveFront();
     deque.AddBack(1);
     Assert.AreEqual(1, deque.RemoveFront());
 }
开发者ID:telefunkenvf14,项目名称:Deque,代码行数:8,代码来源:DequeTests.cs


注:本文中的Deque.RemoveFront方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。