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

15-07-10 Stack集合、queue集合、hashtable集合

时间:2015-07-16 00:41:11      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:

1.栈:Stack,先进后出,一个一个赋值,一个一个取值,按顺序。

.count           取集合内元素的个数

.push()         将元素一个一个推入集合中//stack集合存入用.push()

.pop()           将元素一个个弹出集合

.clear()         清空集合

技术分享
 Stack s = new Stack();//先存入的后取出
            s.Push(1);
            s.Push(2);
            s.Push(3);

            Console.WriteLine(s.Pop()); //也可用foreach循环输出
            Console.WriteLine(s.Pop());
技术分享

技术分享

2.queue:先存入的先输出,一个一个的赋值一个一个的取值,按照顺序。

.count              取集合内元素的个数

.Enqueue()      进队列集合//存入元素

.Dequeue()      出队列集合

.clear               清空集合

技术分享
 //Queue q = new Queue();
            //q.Enqueue(1);
            //q.Enqueue(2);
            //q.Enqueue(3);

            //Console.WriteLine(q.Dequeue());
            //Console.WriteLine(q.Dequeue());
技术分享

技术分享

3.hashtable:先进后出,一个一个赋值,但只能一起取值。

.Add(,)              添加key和元素//用于元素添加

.Remove()        将括号内的元素移除

.contains()       判断集合中是否有括号内的元素

.count               计算集合中元素的个数

技术分享
Hashtable h = new Hashtable();

            h.Add(1, "ss");
            h.Add(2, "dd");

            foreach (int i in h.Keys)//输出key
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("------");
            foreach (string s in h.Values)//输出key所对应的值
            {
                Console.WriteLine(s);
            }

            Console.WriteLine("-----------");
            Console.WriteLine(h.Count);//输入一共元素的个数
            
技术分享

技术分享

15-07-10 Stack集合、queue集合、hashtable集合

标签:

原文地址:http://www.cnblogs.com/jia520110270/p/4649843.html

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