栈stack和队列queue
这里只谈一下栈和队列的简单运用和理解。
//栈Stack 压栈push 出栈pop 获取栈顶peek 判断有没有contains
Stack<int> shuzi = new Stack<int>();
shuzi.Push (10);
shuzi.Push (20);
shuzi.Push (30);
shuzi.Push (40);
shuzi.Push (50);
shuzi.Push (60);
Console.WriteLine (shuzi.Pop());//60
Console.WriteLine (shuzi.Pop());//50
Console.WriteLine (shuzi.Peek());//40
Console.WriteLine (shuzi.Contains(50));//False
//队列Queue 入队Enqueue 出队Dequeue 判断有没有contains
Queue<string> str = new Queue<string>();
str.Enqueue ("A");
str.Enqueue ("B");
str.Enqueue ("C");
str.Enqueue ("D");
str.Enqueue ("E");
str.Enqueue ("F");
Console.WriteLine (str.Dequeue());//A
Console.WriteLine (str.Dequeue());//B
Console.WriteLine (str.Contains("A"));//False
栈是先进后出,队列是先进先出。
2018.10.24,来到CSDN博客写的第二篇笔记,本人目前还是初学者,只分享一些简单的基础知识,也是为了做一下学习笔记,望读者加以指正,谢谢!