Advertisement
thorax232

Java - Counting Sort

Nov 13th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.33 KB | None | 0 0
  1. public static long countingSort(int[] list) {
  2.     int high = 999;
  3.     int low = 0;
  4.     int[] counts = new int[high - low + 1];
  5.    
  6.     for(int i = 0; i < counts.length; i++) {
  7.         counts[i] = 0;
  8.     }
  9.        
  10.     int x = 0;
  11.     for(int i = low; i <= high; i++) {
  12.         list[x] = i;
  13.         x += 1;
  14.         counts[i - low] = counts[i - low] - 1;
  15.     }
  16.        
  17.     return list;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement