Sort int array elements from High to Low : Java

/**
   * Sort int array elements from high to low.
   * http://www.victorbyte.net/
   * void method
   */
 public static void arraySortHighToLow(int[] array)
 {
  int temp = 0;
  for (int loop = array.length - 2, index = array.length - 1; loop >= 0 ; loop--)
    {
     if (array[index] > array[loop]) 
     {
      temp = array[index];
      array[index] = array[loop];
      array[loop] = temp;
     }
     
     if (loop == 0)  loop = --index; // reset loop
    }
  
  return;
 }

Absolute Java (4th Edition)

This entry was posted in algorithms, java. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *