• 数据结构和算法基础之队列的链式存储


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApplication1
    {
        public class QueueNode<T>
        {
            public T Data;
            public QueueNode<T> Next;
    
            public QueueNode()
            {
                Data = default(T);
                Next = null;
            }
    
            public QueueNode(T data)
            {
                Data = data;
                Next = null;
            }
        }
        /// <summary>
        /// 链式队列
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public class LinkQueue<T>
        {
            public QueueNode<T> Head;
            public QueueNode<T> Front;
            public QueueNode<T> Rear;
            public int Count;
    
            public LinkQueue()
            {
                Head = null;
                Front = null;
                Count = 0;
            }
    
            /// <summary>
            /// 入栈
            /// </summary>
            public void Enqueue(T data)
            {
                QueueNode<T> node = new QueueNode<T>(data);
                if(Head==null)
                {
                    Head = new QueueNode<T>();
                    Front = Head;
                    Rear = Head;
                }
                Count++;
                Rear.Next = node;
                Rear = node;
                node.Next = null;
            }
    
            /// <summary>
            /// 出栈
            /// </summary>
            /// <returns></returns>
            public  T Dequeue()
            {
                if(Count>0)
                {
                    T data = Front.Next.Data;
                    Head = Front.Next;
                    Front = Head;
                    Count--;
                    return data;
    
                }
                return default(T);
            }
    
    
        }
    }
  • 相关阅读:
    找正环的最快方法!!
    树重量的神仙问题
    2019 ICPC南昌网络赛 B题
    洛谷p-1522又是Floyd
    poj3471
    洛谷p1119--灾难后重建(Floyd不仅仅是板子)
    并查集的超市问题---溜TM的
    利用主席树 搞区间不同值的和
    acwing 102 -利用二分枚举区间平均值
    Week__8
  • 原文地址:https://www.cnblogs.com/weiqiangwaideshijie/p/10544503.html
Copyright © 2020-2023  润新知