zoukankan      html  css  js  c++  java
  • 数据结构和算法基础之队列的顺序存储

    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);
            }
        }
    }
  • 相关阅读:
    RSA加密系统
    安装homebrew
    go helloworld
    下载文件checksum
    6月3日
    6月1日
    5月30日
    5月28日
    5月26日
    5月24日
  • 原文地址:https://www.cnblogs.com/weiqiangwaideshijie/p/10544496.html
Copyright © 2011-2022 走看看