Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SortedList&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="collection">The collection to copy into the sorted list.</param>
        public SortedList(IEnumerable <T> collection)
        {
            data = new VisitableList <T>();

            IEnumerator <T> enumerator = collection.GetEnumerator();

            while (enumerator.MoveNext())
            {
                this.Add(enumerator.Current);
            }
        }
Пример #2
0
        /// <summary>
        /// Compares the current instance with another object of the same type.
        /// </summary>
        /// <param name="obj">An object to compare with this instance.</param>
        /// <returns>
        /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than obj. Zero This instance is equal to obj. Greater than zero This instance is greater than obj.
        /// </returns>
        /// <exception cref="T:System.ArgumentException">obj is not the same type as this instance. </exception>
        public int CompareTo(object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }

            if (obj.GetType() == this.GetType())
            {
                VisitableList <T> l = obj as VisitableList <T>;

                return(this.Count.CompareTo(l.Count));
            }
            else
            {
                return(this.GetType().FullName.CompareTo(obj.GetType().FullName));
            }
        }
Пример #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Heap&lt;T&gt;"/> class.
        /// </summary>
        /// <param name="type">The type of heap.</param>
        /// <param name="capacity">The initial capacity of the Heap.</param>
        /// <param name="comparer">The comparer to use.</param>
        public Heap(HeapType type, int capacity, IComparer <T> comparer)
        {
            if (comparer == null)
            {
                throw new ArgumentNullException("comparer");
            }

            thisType = type;

            data = new VisitableList <T>(capacity);
            data.Add(default(T));              // Add a dummy item so our indexing starts at 1

            if (type == HeapType.MinHeap)
            {
                comparerToUse = comparer;
            }
            else
            {
                comparerToUse = new ReverseComparer <T>(comparer);
            }
        }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SortedList&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="capacity">The intial capacity of the sorted list.</param>
 /// <param name="comparer">The comparer to use.</param>
 public SortedList(int capacity, IComparer <T> comparer)
 {
     data = new VisitableList <T>(capacity);
     this.comparerToUse = comparer;
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SortedList&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="capacity">The intial capacity of the sorted list.</param>
 public SortedList(int capacity)
 {
     data = new VisitableList <T>(capacity);
     this.comparerToUse = Comparer <T> .Default;
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SortedList&lt;T&gt;"/> class.
 /// </summary>
 /// <param name="comparer">The comparer to use.</param>
 public SortedList(IComparer <T> comparer)
 {
     data = new VisitableList <T>();
     this.comparerToUse = comparer;
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SortedList&lt;T&gt;"/> class.
 /// </summary>
 public SortedList()
 {
     data          = new VisitableList <T>();
     comparerToUse = Comparer <T> .Default;
 }