Depoll.com: Programming, School, Life.

Sorting Algorithm Visualizations
By: David Eitan Poll

 

Home
Download
Screenshots

Adding your sorts

Algorithms
-Bubble Sort
-Comb Sort
-Gnome Sort
-Heap Sort
-Insertion Sort
-Merge Sort
-Odd/Even Sort
-Quick Sort
-Quick Sort with Bubble Sort
-Radix Sort
-Rob (Random) Sort
-Selection Sort
-Shaker Sort
-Shear Sort
-Shell Sort

Donation:

Insertion Sort

Description:
The Insertion Sort is another one of the most common and simple to understand sorting algorithms.  It traverses the list, and while doing so, makes sure that each item is in its place by swapping elements back until they are in the correct position.  This works because as the list is traversed, the list up to that point must be sorted.

Efficiency: O(N2)

Source:

public class InsertionSort: SortMethod
{
   public override void sort(int[] list)
   {
      for(int x=0;x<list.Length;x++)
      {
         int index=x;
         while(index>0&&list[index]<list[index-1])
         {
            NumIterations++;
            NumComparisons++;
            swap(list,index,index-1);
            pause(x,index-1);
            index--;
         }
         pause(x);
      }
   }
   public override string ToString()
   {
      return "Insertion Sort";
   }
}