Insert Sort int Array - CSharp Data Structure Algorithm

CSharp examples for Data Structure Algorithm:Sort

Description

Insert Sort int Array

Demo Code


using System.Linq;
using System.Collections.Generic;
using System;/*w  ww  . jav a 2  s  . c  o  m*/

public class Main{
        static public void Insert_Sort(int[] array) {

            int cnt = array.Length;

            if (cnt == 1 || cnt == 0)
                return;

            for (int ii = 1; ii < cnt; ++ii) {
                var elem = array[ii];

                int jj;
                for (jj = ii - 1; jj >= 0; --jj) {

                    if (array[jj] < elem)
                        break;

                    array[jj + 1] = array[jj];
                }

                array[jj + 1] = elem;
            }
        }
}

Related Tutorials