My friends, I recently stepped up writing some C # algorithms. Select sorting and insert the algorithm I have introduced. Now we are introducing the hill sorting feature. In the future, I will introduce other algorithms in sequence.
Hill sorting is to segment the group for insertion sorting.
If you want to improve your C # programming skills, we can discuss with each other.
For example, the following program does not implement polymorphism. Using System;
Public class ShellSorter
{
Public void Sort (int [] list)
{
Int inc;
For (inc = 1; inc <= list. Length/9; inc = 3 * inc + 1 );
For (; inc> 0; inc/= 3)
{
For (int I = inc + 1; I <= list. Length; I + = inc)
{
Int t = list [I-1];
Int j = I;
While (j> inc) & (list [j-inc-1]> t ))
{
List [J-1] = list [j-inc-1];
J-= inc;
}
List [J-1] = t;
}
}
}
}
Public class MainClass
{
Public static void Main ()
{
Int [] iArrary = new int };
ShellSorter sh = new ShellSorter ();
Sh. Sort (iArrary );
For (int m = 0; m <= 13; m ++)
Console. WriteLine ("{0}", iArrary [m]);
}
}
It has been compiled.