Beispiel #1
0
        /// <summary>
        /// Insirt cell and sell priority
        /// </summary>
        /// <param name="priority">Cell Scale</param>
        /// <param name="item">Cell</param>
        public void Insert(T priority, T1 item)
        {
            var node = new TreeNodeVal <T, T1>(priority, item);

            items.Add(node);
            Increase(items.Count - 1);
        }
Beispiel #2
0
        /// <summary>
        /// Increase a cells rank
        /// </summary>
        /// <param name="rank">Cell Rank</param>
        void Increase(int rank)
        {
            int parentRank = (int)Math.Floor(((float)(rank - 1) / 2));

            if (parentRank > 0)
            {
                TreeNodeVal <T, T1> parent = items.ElementAt(parentRank), node = items.ElementAt(rank);
                if (parent.Key.CompareTo(node.Key) >= 0)
                {
                    var temp = items[rank];
                    items[rank]       = items[parentRank];
                    items[parentRank] = temp;
                    Increase(parentRank);
                }
            }
        }