队列(Queue)
队列是 一个先进先出的对象集合。
Queue q1 = new Queue();
关键字 队列名 格式
队列的一些方法
Count: 获取 Queue 中包含的元素个数
Clear():从 Queue 中移除所有的元素
Contains( object obj ):判断某个元素是否在 Queue 中
Dequeue():移除并返回在 Queue 的开头的对象
Enqueue( object obj ):向 Queue 的末尾添加一个对象
ToArray():复制 Queue 到一个新的数组中
TrimToSize():设置容量为 Queue 中元素的实际个数
队列的进阶,也就是队列的升级
ConcurrentQueue<T>
ConcurrentQueue<T>队列是一个高效的线程安全的队列,是.Net Framework 4.0,System.Collections.Concurrent命名空间下的一个数据结构。
--------------------------------
Stack 栈
栈 是一种 后进先出的线性结构,
栈就相当于,我们在小时候玩的玩具枪的子弹夹一样,从头开始添加,从头弹出,栈的原理就是这样
栈中插入数据元素的过程称为入栈(push)
删除元素的过程称为出栈(pop)
栈的方法和属性
Count: 获取 Stack 中包含的元素个数
Clear():从 Stack 中移除所有的元素
Contains( object obj ):判断某个元素是否在 Stack 中
peek();返回Stack 的顶部的,但不移出它
pop():移除并返回在 Stack 的顶部的对象
Push( object obj ):向 Stack 的顶部添加一个对象
ToArray():复制Stack 到一个新的数组中