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:

Bubble Sort

Description:
The Bubble Sort is one of the most common and simple to understand sorting algorithms.  It works by traversing the list (L) N times.  As it traverses the list, it checks the current element (L[x]) against the next element (L[x+1]). If L[x]>L[x+1], the elements are swapped.  Thus, the largest element gets carried to the end of the list.  By repeating this process N times, the list is sorted.

Efficiency: O(N2)

Source:

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