コード例 #1
0
        /// <summary>
        /// <para> Reverses the SortedLinkedList with its current <see cref="IComparer{T}"/></para>
        /// <para> Expected Runtime: O(n), where n is the size of the list.</para>
        /// </summary>
        public new void Reverse()
        {
            this.reversalFactor *= -1;
            SortedLinkedList <T> newSortedMethod = new SortedLinkedList <T>();

            foreach (T value in this)
            {
                newSortedMethod.Add(value);
            }

            this.Clear();

            foreach (T value in newSortedMethod)
            {
                this.Add(value);
            }
            newSortedMethod.Dispose();
        }
コード例 #2
0
        /// <summary>
        /// <para>Sorts the list with the new <see cref="IComparer{T}"/></para>
        /// <para>Expected Runtime: O(n), where n is the size of the list.</para>
        /// </summary>
        /// <param name="newComparer"></param>
        public void Sort(IComparer <T> newComparer)
        {
            SortedLinkedList <T> newSortedMethod = new SortedLinkedList <T>(newComparer);

            foreach (T value in this)
            {
                newSortedMethod.Add(value);
            }

            //TODO: Should this just return this new copy?

            this.Clear();
            this.Comparer = newComparer;

            foreach (T value in newSortedMethod)
            {
                this.Add(value);
            }
            newSortedMethod.Dispose();
        }