Stack集合、queue集合、hashtable集合

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());

Stack集合、queue集合、hashtable集合

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());

Stack集合、queue集合、hashtable集合

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);//输入一共元素的个数
            

Stack集合、queue集合、hashtable集合