• 队列Queue


         Queue对象类似于数据结构中的队列,先进先出(FIFO)。

        

    /*
      Example11_10.cs illustrates the use of a Queue
    */
    
    using System;
    using System.Collections;
    
    class Example11_10
    {
    
      public static void Main()
      {
    
        // create a Queue object
        Queue myQueue = new Queue();
    
        // add elements to myQueue using the Enqueue() method
        myQueue.Enqueue("This");
        myQueue.Enqueue("is");
        myQueue.Enqueue("a");
        myQueue.Enqueue("test");
    
        // display the elements in myQueue
        foreach (string myString in myQueue)
        {
          Console.WriteLine("myString = " + myString);
        }
    
        // get the number of elements in myQueue using the
        // Count property
        int numElements = myQueue.Count;
    
        for (int count = 0; count < numElements; count++)
        {
    
          // examine an element in myQueue using Peek()
          Console.WriteLine("myQueue.Peek() = " +
            myQueue.Peek());
    
          // remove an element from myQueue using Dequeue()
          Console.WriteLine("myQueue.Dequeue() = " +
            myQueue.Dequeue());
    
        }
    
      }
    
    }
    
  • 相关阅读:
    二叉搜索树
    【树】List Leaves
    模板——dijkstra单源最短路
    余数求和——除法分块
    倍增——ST表
    线段树——内存池
    线段树——模板
    洛谷 P1498 南蛮图腾
    洛谷 P2199 最后的迷宫
    洛谷 P1495 中国剩余定理
  • 原文地址:https://www.cnblogs.com/djcsch2001/p/2039427.html
Copyright © 2020-2023  润新知