c#中queue队列用法
来源:互联网 发布:卸载预装软件 编辑:程序博客网 时间:2024/06/08 06:55
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace QueueSample{ class Program { static void Main(string[] args) { Queue<string> numbers = new Queue<string>(); numbers.Enqueue("one"); numbers.Enqueue("two"); numbers.Enqueue("three"); numbers.Enqueue("four"); numbers.Enqueue("five"); // A queue can be enumerated without disturbing its contents. foreach (string number in numbers) { Console.WriteLine(number); } Console.WriteLine("\nDequeuing '{0}'", numbers.Dequeue()); Console.WriteLine("Peek at next item to dequeue: {0}", numbers.Peek()); Console.WriteLine("Dequeuing '{0}'", numbers.Dequeue()); // Create a copy of the queue, using the ToArray method and the // constructor that accepts an IEnumerable<T>. Queue<string> queueCopy = new Queue<string>(numbers.ToArray()); Console.WriteLine("\nContents of the first copy:"); foreach (string number in queueCopy) { Console.WriteLine(number); } // Create an array twice the size of the queue and copy the // elements of the queue, starting at the middle of the // array. string[] array2 = new string[numbers.Count * 2]; numbers.CopyTo(array2, numbers.Count); // Create a second queue, using the constructor that accepts an // IEnumerable(Of T). Queue<string> queueCopy2 = new Queue<string>(array2); Console.WriteLine("\nContents of the second copy, with duplicates and nulls:"); foreach (string number in queueCopy2) { Console.WriteLine(number); } Console.WriteLine("\nqueueCopy.Contains(\"four\") = {0}", queueCopy.Contains("four")); Console.WriteLine("\nqueueCopy.Clear()"); queueCopy.Clear(); Console.WriteLine("\nqueueCopy.Count = {0}", queueCopy.Count); Console.ReadLine(); } }}
阅读全文
0 0
- c#中queue队列用法
- C#队列Queue用法实例分析
- C++ 中queue(队列)的用法
- c#中 Queue队列类 理解
- C#队列Queue详解
- C# 队列(Queue)
- C# 浅析Queue队列
- C#队列(Queue)
- C# 队列(Queue)
- C# 队列 QUEUE
- C#数据结构--队列Queue
- C# 队列 Queue
- jQuery中queue和dequeue的用法 (juery 队列)
- C++ 中 queue(队列)的用法(常用)
- C++ 队列queue的用法
- Java 队列(Queue)用法
- 队列(Queue)入门用法
- C++ 队列queue的用法
- 在Servlet中向客户端写Cookie信息
- 安卓自定义滑动解锁控件
- LeetCode | 28. Implement strStr()——寻找子串
- java_web环境部署
- Linux图形界面当中,将调整屏幕大小的解决办法。
- c#中queue队列用法
- ofstream和ifstream详细用法
- 最短路径算法----Bellman-ford和SPFA算法
- 离散题目10
- uva 12096The SetStack Computer
- CSS里的浏览器前缀
- TCP socket编程实现
- Vue.js学习之路—使用vue-cli搭建项目
- 排序算法总结(11)--总结