Click here to Skip to main content
15,886,362 members
Articles / Programming Languages / C# 4.0

Util Library and Extension Methods

Rate me:
Please Sign up or sign in to vote.
4.86/5 (49 votes)
7 May 2013CPOL2 min read 47.8K   1.6K   131  
A simple Util library.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NumberExtensions.Collections.SortStrategies
{
    internal class InsertionSort
    {
        internal static void Sort(ref IList<int> numbers)
        {
            int i, j;
            int index;
            for (i = 1; i < numbers.Count; i++)
            {
                index = numbers[i];
                j = i;
                while ((j > 0) && (numbers[j - 1] > index))
                {
                    numbers[j] = numbers[j - 1];
                    j = j - 1;
                }
                numbers[j] = index;
            }
        }
        internal static void Sort(ref IList<long> numbers)
        {
            int i, j;
            long index;
            for (i = 1; i < numbers.Count; i++)
            {
                index = numbers[i];
                j = i;
                while ((j > 0) && (numbers[j - 1] > index))
                {
                    numbers[j] = numbers[j - 1];
                    j = j - 1;
                }
                numbers[j] = index;
            }
        }
        internal static void Sort(ref IList<decimal> numbers)
        {
            int i, j;
            decimal index;
            for (i = 1; i < numbers.Count; i++)
            {
                index = numbers[i];
                j = i;
                while ((j > 0) && (numbers[j - 1] > index))
                {
                    numbers[j] = numbers[j - 1];
                    j = j - 1;
                }
                numbers[j] = index;
            }
        }
        internal static void Sort(ref IList<float> numbers)
        {
            int i, j;
            float index;
            for (i = 1; i < numbers.Count; i++)
            {
                index = numbers[i];
                j = i;
                while ((j > 0) && (numbers[j - 1] > index))
                {
                    numbers[j] = numbers[j - 1];
                    j = j - 1;
                }
                numbers[j] = index;
            }
        }
        internal static void Sort(ref IList<double> numbers)
        {
            int i, j;
            double index;
            for (i = 1; i < numbers.Count; i++)
            {
                index = numbers[i];
                j = i;
                while ((j > 0) && (numbers[j - 1] > index))
                {
                    numbers[j] = numbers[j - 1];
                    j = j - 1;
                }
                numbers[j] = index;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Schneider Electric, GTCI Bangalore
India India
Music is my passion,
Apart from programming I like to read a lot.

Comments and Discussions