Skip to main content

Posts

Showing posts with the label counting sort

Counting Sort

I did not spend a significant amount of time removing potential issues with this code, but then, neither do most examples of the Counting Sort; there are more interesting algorithms ahead.  The most obvious flaws in this particular implementation are as follows: It cannot handle negative integers It is designed only for integers.  using System; namespace Algorithms {     class CountingSort     {         public int[] Sort()         {             //creates array             int[] arrayToSort = { 2, 1, 2, 1, 3, 0, 3, 4, 4, 3, 0, 2, 1, 3, 5, 1, 3 };             //create array for bucket             int min = 0;              int max = 0;             for (int counter = 0; counter < arrayToSort.Length; counter++)   ...