예제 #1
0
        /// <summary>
        /// Adds an item to the list, resizes if needed and sorts the collection
        /// </summary>
        /// <param name="element"></param>
        public void Add(T element)
        {
            if (element == null)
            {
                throw new ArgumentNullException();
            }

            if (this.innerCollection.Length == this.size)
            {
                Resize();
            }

            this.innerCollection[size] = element;
            this.size++;
            QuickSorter.Sort(this.innerCollection, 0, size - 1, this.comparison);
        }
예제 #2
0
        /// <summary>
        /// Adds the items to the list, resizes if needed and finally sorts the list
        /// </summary>
        /// <param name="collection"></param>
        public void AddAll(ICollection <T> collection)
        {
            if (collection.Any(c => c == null))
            {
                throw new ArgumentNullException("An item in the collection is null!");
            }

            if (this.size + collection.Count >= this.innerCollection.Length)
            {
                MultiResize(collection);
            }

            foreach (var element in collection)
            {
                this.innerCollection[this.size] = element;
                this.size++;
            }

            QuickSorter.Sort(this.innerCollection, 0, this.size - 1, this.comparison);
        }