⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 binarypriorityqueue!1.cs

📁 破解的飞信源代码
💻 CS
字号:
namespace NCindy.DataStructures
{
    using System;
    using System.Collections;
    using System.Collections.Generic;

    public class BinaryPriorityQueue<T> : IQueue<T>, ICollection<T>, IEnumerable<T>, IEnumerable, ICloneable
    {
        protected IComparer<T> comparer;
        protected IList<T> innerList;

        public BinaryPriorityQueue() : this(Comparer<T>.get_Default())
        {
        }

        public BinaryPriorityQueue(IComparer<T> comparer)
        {
            this.innerList = new List<T>();
            this.comparer = comparer;
        }

        protected BinaryPriorityQueue(IList<T> prototype, IComparer<T> comparer, bool deepCopy)
        {
            this.innerList = new List<T>();
            if (deepCopy)
            {
                this.innerList = new List<T>(prototype);
            }
            else
            {
                this.innerList = prototype;
            }
            this.comparer = comparer;
        }

        public void Add(T item)
        {
            this.Enqueue(item);
        }

        public void Clear()
        {
            this.innerList.Clear();
        }

        public object Clone()
        {
            return new BinaryPriorityQueue<T>(this.innerList, this.comparer, true);
        }

        public bool Contains(T item)
        {
            return this.innerList.Contains(item);
        }

        public void CopyTo(T[] array, int arrayIndex)
        {
            this.innerList.CopyTo(array, arrayIndex);
        }

        public T Dequeue()
        {
            T local = this.innerList.get_Item(0);
            this.innerList.RemoveAt(0);
            return local;
        }

        public void Enqueue(T item)
        {
            if (this.innerList.get_Count() == 0)
            {
                this.innerList.Add(item);
            }
            else
            {
                int num = 0;
                int num2 = this.innerList.get_Count() - 1;
                do
                {
                    int num3 = num + ((num2 - num) / 2);
                    int num4 = this.comparer.Compare(item, this.innerList.get_Item(num3));
                    if (num4 < 0)
                    {
                        num2 = num3;
                    }
                    else if (num4 == 0)
                    {
                        num = num2 = num3;
                    }
                    else
                    {
                        num = num3 + 1;
                    }
                }
                while ((num2 - num) > 0);
                this.innerList.Insert(num2, item);
            }
        }

        public IEnumerator<T> GetEnumerator()
        {
            return this.innerList.GetEnumerator();
        }

        public T Peek()
        {
            if (this.innerList.get_Count() > 0)
            {
                return this.innerList.get_Item(0);
            }
            return default(T);
        }

        public bool Remove(T item)
        {
            return this.innerList.Remove(item);
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return this.innerList.GetEnumerator();
        }

        public int Count
        {
            get
            {
                return this.innerList.get_Count();
            }
        }

        public bool IsReadOnly
        {
            get
            {
                return this.innerList.get_IsReadOnly();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -