码迷,mamicode.com
首页 > 其他好文 > 详细

Stack集合 Queue队列集合 Hashtable哈希表

时间:2016-10-16 21:43:14      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:

Stack集合 干草堆集合 栈集合
栈;stack,先进后出,一个一个赋值,一个一个取值,安装顺序来.
属性和方法
实例化 初始化
Stack st = new Stack();

添加元素

 1  个数
 2             Console.WriteLine(st.Count);
 3             只要使用一次pop方法,就会从最后一个元素开始排除 弹出
 4             Console.WriteLine(st.Pop());
 5             Console.WriteLine(st.Count);
 6             只想查看不弹出
 7             Console.WriteLine(st.Peek());
 8             foreach(int aa in st)//遍历集合
 9             {
10                 Console.WriteLine(aa);
11             }
12             Console.WriteLine(st.Count);

个数
Console.WriteLine(st.Count);
只要使用一次pop方法,就会从最后一个元素开始排除 弹出
Console.WriteLine(st.Pop());
Console.WriteLine(st.Count);
只想查看不弹出
Console.WriteLine(st.Peek());
foreach(int aa in st)//遍历集合
{
 Console.WriteLine(aa);
}
Console.WriteLine(st.Count);

Queue队列集合

先进先出
实例化 初始化
Queue que = new Queue();
添加元素
que.Enqueue(5);
que.Enqueue(2);
que.Enqueue(9);
que.Enqueue(8);
que.Enqueue(1);
移除一个元素 从头开始
que.Dequeue();

个数
Console.WriteLine(que.Count);

foreach(int aa in que)
{
 Console.WriteLine(aa);
}

Hashtable哈希表
先进后出,一个一个赋值,但只能一起取值

实例化 初始化
Hashtable ht = new Hashtable();

添加元素

1 ht.Add(1, "张三");
2             ht.Add(2, "李四");
3             ht.Add(3, "王五");
4             ht.Add(4, "赵六");
5             ht.Add(5, "丰七");
6             ht.Add(6, "钱八");

读取

1 foreach (int aa in ht.Keys)//单纯的存储key的集合
2             {
3                 Console.WriteLine(aa);
4             }
5             foreach (string bb in ht.Values)
6             {
7                 Console.WriteLine(bb);
8             }

使用枚举类型进行读取,排列成表格

1 IDictionaryEnumerator ide = ht.GetEnumerator();
2             while (ide.MoveNext())
3             {
4                 Console.WriteLine(ide.Key + "\t" + ide.Value);
5             }

 

Stack集合 Queue队列集合 Hashtable哈希表

标签:

原文地址:http://www.cnblogs.com/1030351096zzz/p/5967737.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!