Why Doesn't My Sort Work!?

Reply

Join Date: Nov 2004
Posts: 2
Reputation: josirucu is an unknown quantity at this point 
Solved Threads: 0
josirucu josirucu is offline Offline
Newbie Poster

Why Doesn't My Sort Work!?

 
0
  #1
Nov 18th, 2004
WHAT IS WRONG HERE?WHY WON'T THIS SORT?

public class bubble
{

public static void main (String[] args)
{
boolean Finished;
int[] intRand = new int[11];
int[] unSorted = new int[11];
int intStore;
int i;
Finished = false;
i = 1;
while (i < 11)
{
intRand[i] = (int)(java.lang.Math.random() * 100);
unSorted[i] = intRand[i];
i = i + 1;
}

do
{
Finished = true;
for (i = 2; i < 11; ++i)
{
if (intRand[i] < intRand[i-1])
{
intStore = intRand[i];
intRand[i] = intRand[i-1];
intRand[i-1] = intStore;
Finished = false;
}
}

}
while (Finished==true );

System.out.println("Unsorted Sorted");
i = 1;
while (i < 11)
{
System.out.print(unSorted[i] + "\t"+ "\t");
System.ouWHATt.println(intRand[i]);
i = i + 1;
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 89
Reputation: MrScruff is an unknown quantity at this point 
Solved Threads: 0
MrScruff's Avatar
MrScruff MrScruff is offline Offline
Junior Poster in Training

Re: Why Doesn't My Sort Work!?

 
0
  #2
Nov 18th, 2004
  1. package untitled4;
  2.  
  3. import java.util.*;
  4.  
  5. public class bubble
  6. {
  7.  
  8. public static void main (String[] args)
  9. {
  10.  
  11. int[] intRand = new int[11];
  12. int[] unSorted = new int[11];
  13.  
  14.  
  15. int i;
  16. i = 1;
  17. while (i < 11)
  18. {
  19. intRand[i] = (int)(java.lang.Math.random() * 100);
  20. unSorted[i] = intRand[i];
  21. i = i + 1;
  22. }
  23. Arrays.sort(intRand);
  24. System.out.println("Hello");
  25. for(i = 0; i<intRand.length;)
  26. {
  27. System.out.print(unSorted[i] + "\t"+ "\t");
  28. System.out.println(intRand[i]);
  29. i++;
  30. }
  31. }
  32. }
A lot more simpler dontcha think? Kinda ditched most of your code though.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC