zoukankan      html  css  js  c++  java
  • 《Queue,Stack,SortedList》集合

    Queue(队列)表示对象的先进先出集合,默认初始容量32。

    using System;

    using System.Collections;

     

    namespace tQueue

    {

        class Test

        {

            static void Main()

            {

                Queue queue = new Queue();

                queue.Enqueue("广告史");

                queue.Enqueue("市场调研");

                queue.Enqueue("传播学");

                Console.WriteLine("队列开始处是{0}",queue.Peek());

                Console.WriteLine(queue.Dequeue());//移除并返回开始处得的对象

                queue.TrimToSize();

                Console.WriteLine("队列中的元素数量为:{0},包含:",queue.Count);

                IEnumerator e = queue.GetEnumerator();

                while (e.MoveNext())

                {

                    Console.WriteLine("{0}", e.Current);

                }

                Console.ReadKey();

            }

        }

    }


    SortedList(排序表)表示键/值对的集合,按键排序并可按照键和索引访问,和Hashtable很相似,最重要的特点就是排序性。

     

    using System;

    using System.Collections;

    namespace tSortedList

    {

        class Program

        {

            static void Main(string[] args)

            {

                SortedList sortarr = new SortedList();

                sortarr.Add("2","语文");

                sortarr.Add("3""数学");

                sortarr.Add("1""化学");

                sortarr.Add("5""生物");

                sortarr.Add("4""英语");

                Console.WriteLine("SortedList表中包含的元素数为{0}",sortarr.Count);

                Console.WriteLine("表中的元素为:");

                for (int i = 0; i < sortarr.Count; i++)

                {

                    Console.WriteLine("{0}-{1}", sortarr.GetKey(i), sortarr.GetByIndex(i));

                }

                Console.ReadKey();

            }

        }

    }


    Stack(栈)表示对象后进先出的集合。默认初始容量32

    using System;

    using System.Collections;

     

    namespace tStack

    {

        class Program

        {

            static void Main()

            {

                Stack stack = new Stack();

                stack.Push("广告");

                stack.Push("广告文案");

                stack.Push("视觉传播");

                Console.WriteLine("堆栈中的元素数量为:{0}",stack.Count);

                Console.WriteLine("堆栈中的元素为");

                IEnumerator e = stack.GetEnumerator();

                while (e.MoveNext())

                {

                    Console.WriteLine(e.Current);

                }

                Console.ReadKey();

            }

        }

    }

     

  • 相关阅读:
    Leetcode 230 Kth Smallest Element in a BST
    codeforces Round #259(div2) C解题报告
    poj 3041(最大匹配问题)
    SpringMVC从Controller跳转到还有一个Controller
    倒计时相关函数 php
    HDU 1575 Tr A(矩阵高速幂)
    poj3468 A Simple Problem with Integers
    奇妙的自慰帽子
    Android 用户登录界面
    泛泰A860(高通8064 cpu 1080p) 刷4.4专用中文recovery TWRP2.7.1.2版(三版通刷)
  • 原文地址:https://www.cnblogs.com/rohelm/p/2384097.html
Copyright © 2011-2022 走看看