static void Main(string[] args)
        {
            RedBlackTreeList <int> tree = new RedBlackTreeList <int>();

            for (int i = 1; i <= 10; i++)
            {
                tree.Add(i);
            }

            tree.Remove(9);

            bool contains = tree.ContainsKey(5);

            Console.WriteLine("Does value exist? " + (contains ? "yes" : "no"));

            uint count = tree.Count;

            tree.Greatest(out int greatest);
            tree.Least(out int least);
            Console.WriteLine($"{count} elements in the range {least}-{greatest}");

            Console.WriteLine("Values: " + string.Join(", ", tree.GetEnumerable()));

            Console.Write("Values: ");
            foreach (EntryList <int> node in tree)
            {
                Console.Write(node + " ");
            }

            Console.ReadKey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the specified items to the priority queue with the specified priority.
        /// </summary>
        /// <param name="items">The items.</param>
        /// <param name="priority">The priority.</param>
        /// <remarks>
        /// 	<b>Notes to Inheritors: </b>
        /// Derived classes can override this method to change the behavior of the <see cref="AddPriorityGroup"/> method.
        /// </remarks>
        protected virtual void AddPriorityGroupItem(IList<TValue> items, TPriority priority)
        {
            LinkedList<TValue> currentValues;

            if (tree.TryGetValue(priority, out currentValues))
            {
                for (var i = 0; i < items.Count; i++)
                {
                    currentValues.AddLast(items[i]);
                }
            }
            else
            {
                currentValues = new LinkedList<TValue>(items);
                tree.Add(priority, currentValues);
            }
        }