Im trying to organize random numbers in an array from least to greatest. I came up with a loop which I thought should work but has a lot of logic errors.
for(int z=0; z<=999;z++){
for(w=1; w<=999;w++){
if(z<w){
if(numberArray[z]<numberArray[w])
temp=numberArray[w];
}
}
numberArray[z]=temp;
}
Can anyone tell me how to fix this or an algorithm of their own for doing this?
Arrays.sort()
is a quick and easy way.Also consider PriorityQueues if you need something a little more robust!
This link is another question on SO with a great answer.