using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { /// <summary> /// 顺序队列 /// </summary> public class OrderQueue<T> { public T[] DataArry; /// <summary> /// 对头 /// </summary> public int Front; /// <summary> /// 队尾 /// </summary> public int Rear; public int Count; public int MaxLength { get { return DataArry.Length; } } public OrderQueue(int maxLength) { DataArry = new T[maxLength]; Front = -1; Rear = -1; } /// <summary> /// 入队列 /// </summary> public void Enqueue( T data) { if(Count>=MaxLength) { return; } Count++; Rear++; DataArry[Rear] = data; } /// <summary> /// 出队列 /// </summary> public T Dequeue() { if(Count>0) { Count--; Front++; T tempData = DataArry[Front]; return tempData; } return default(T); } } }
原文地址:https://www.cnblogs.com/weiqiangwaideshijie/p/10544496.html
时间: 2024-10-02 01:21:29