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


C# ArrayStack.Peek方法代码示例

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


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

示例1: TestPeakAfterPushPopElement

        public void TestPeakAfterPushPopElement()
        {
            var stack = new ArrayStack<int>();

            stack.Push(10);
            stack.Push(20);
            Assert.AreEqual(20, stack.Peek());
            stack.Pop();
            Assert.AreEqual(10, stack.Peek());
        }
开发者ID:bobosam,项目名称:DataStructures,代码行数:10,代码来源:ArrayStackTests.cs

示例2: Pop_deleteCellReturned

 public void Pop_deleteCellReturned()
 {
     ArrayStack<int> st = new ArrayStack<int>();
     st.Stack(5);
     st.Push(1);
     st.Push(2);
     Console.WriteLine("Количество элементов в стеке: " + st.GetCount);
     Console.WriteLine("Верхний элемент стека: " + st.Peek());
     st.Pop();
     Console.WriteLine("Удален верхний элемент стека \n\n");
     Console.WriteLine("Количество элементов в стеке: " + st.GetCount);
     Console.WriteLine("Верхний элемент стека: " + st.Peek());
 }
开发者ID:Diana04,项目名称:Ishmatova_Diana,代码行数:13,代码来源:UnitTest1.cs

示例3: PushingElementShouldContainElement

        public void PushingElementShouldContainElement()
        {
            var stack = new ArrayStack<int>();

            stack.Push(6);

            Assert.IsTrue(stack.Peek() == 6, "The stack must contain 6.");
            Assert.IsTrue(stack.Count == 1, "The stack count must be 1.");
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:9,代码来源:ArrayStackTests.cs

示例4: Main

        public static void Main(string[] args)
        {
            var stack = new ArrayStack<int>();

            stack.Push(1);
            stack.Push(2);
            stack.Push(3);
            stack.Push(4);

            stack.Pop();
            var array = stack.ToArray();
            Console.WriteLine(stack.Peek());
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:13,代码来源:Program.cs

示例5: PushPeekManyElementsShouldSetCountCorrectlyAndReturnCorrectElement

        public void PushPeekManyElementsShouldSetCountCorrectlyAndReturnCorrectElement()
        {
            ArrayStack<string> stack = new ArrayStack<string>();

            Assert.AreEqual(0, stack.Count, "Count for newly created stack is not correct.");

            for (int i = 0; i < 1000; i++)
            {
                stack.Push(i.ToString());
            }

            for (int i = 1000; i >= 0; i--)
            {
                Assert.AreEqual("999", stack.Peek(), "Peeked element is not correct.");
                Assert.AreEqual(1000, stack.Count, "Count after element peeking is not correct");
            }
        }
开发者ID:ttitto,项目名称:DataStructuresAndAlgorithms,代码行数:17,代码来源:ArrayStackTests.cs

示例6: Main

    // Implement the ADT stack as auto-resizable array.
    // Resize the capacity on demand (when no space is available to add / insert a new element).
    public static void Main()
    {
        var stack = new ArrayStack<int>();

        stack.Push(1);
        stack.Push(2);
        stack.Push(3);
        stack.Push(4);
        Console.WriteLine("Stack: {0}", stack);

        stack.Push(5);
        Console.WriteLine("Push 5...");
        Console.WriteLine("Stack: {0}", stack);

        Console.WriteLine("Peek: {0}", stack.Peek());

        Console.WriteLine("Pop: {0}", stack.Pop());
        Console.WriteLine("Stack: {0}", stack);

        Console.WriteLine("Pop: {0}", stack.Pop());
        Console.WriteLine("Stack: {0}", stack);
    }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:24,代码来源:ArrayStackTest.cs

示例7: Main

	static void Main()
	{
		ArrayStack stack = new ArrayStack(5);
		stack.Push(4);
		stack.Push("This is cool");
		stack.Push(new Node("NodeString"));
		stack.Push(5.356);
		stack.Push('d');
		Console.WriteLine("Stack full? "+stack.IsFull());
		
		for (int i=0; i<stack.Count; i++)
		{
			Console.WriteLine(stack[i]);
		}
		
		stack.Pop();
		stack.Pop();
		stack.Pop();
		stack.Pop();
		Console.WriteLine(stack.Peek());
		stack.Pop();
		Console.WriteLine(stack.IsEmpty());
	}
开发者ID:moosearch,项目名称:Sample-ADTs,代码行数:23,代码来源:Test.cs

示例8: Main

    static void Main()
    {
        var stack = new ArrayStack<int>();

        int[] arr1 = stack.ToArray();

        Console.WriteLine(string.Join(", ", arr1));

        stack.Push(1);
        stack.Push(2);
        stack.Push(3);
        stack.Push(4);
        stack.Push(5);
        stack.Push(6);
        stack.Push(7);
        //Console.WriteLine(stack.Pop());
        //stack.Pop();
        //stack.Pop();
        //stack.Pop();
        //stack.Pop();
        //stack.Pop();
        //Console.WriteLine(stack.Contains(50));
        Console.WriteLine(stack.Peek());
        Console.WriteLine(stack.Count);
        int[] arr = stack.ToArray();
        Console.WriteLine(string.Join(", ", arr));

        var stack1 = new ArrayStack<int>();

        //stack1.Pop();
        var st = new Stack<int>();
        //st.Push(1);
        //st.Push(2);
        //st.Push(3);
        //Console.WriteLine(string.Join(", ", st.ToArray()));
    }
开发者ID:bobosam,项目名称:DataStructures,代码行数:36,代码来源:Tests.cs

示例9: PushElementFromStackWithCapacity1ShouldContainElement

        public void PushElementFromStackWithCapacity1ShouldContainElement()
        {
            var stack = new ArrayStack<int>(1);

            stack.Push(6);

            Assert.IsTrue(stack.Peek() == 6, "The stack must contain 6.");
            Assert.IsTrue(stack.Count == 1, "The stack count must be 1.");
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:9,代码来源:ArrayStackTests.cs

示例10: PeekFromEmptyStackShotuldThrowException

        public void PeekFromEmptyStackShotuldThrowException()
        {
            var stack = new ArrayStack<int>();

            stack.Peek();
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:6,代码来源:ArrayStackTests.cs

示例11: PeekOnEmptyStackShouldThrowException

 public void PeekOnEmptyStackShouldThrowException()
 {
     ArrayStack<int> stack = new ArrayStack<int>(4);
     stack.Peek();
 }
开发者ID:ttitto,项目名称:DataStructuresAndAlgorithms,代码行数:5,代码来源:ArrayStackTests.cs


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