Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

reverse sort

$
0
0
public class Sort extends WrapIt1
{
  public void run()
  {
        //task: reverse the sort,     
        int[] unsorted = new int[100];
    for(int i = 0; i < 100; i++)
      unsorted[i] = (int)(Math.random()*100);
    println("Here are the unsorted numbers:");
    for(int i = 0; i < 100; i++) print(unsorted[i]+" ");
    println();
    int[] sorted = new int[100];
    for(int i = 0; i < 100; i++)
    {
      int hi = -1;
      int hiIndex = -1;
      for(int j = 0; j < 100; j++)
      {
        if(unsorted[j] > hi)
        {
          hi = unsorted[j];
          hiIndex = j;
        }
      }
      sorted[i] = hi;
      unsorted[hiIndex] = -1;
    }
    println("Here are the sorted numbers:");
    for(int i = 0; i < 100; i++) print(sorted[i]+" ");
    println();
  }
}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>