Java first semester programming, could use some help!

OverVolt

Lifer
Aug 31, 2002
14,278
89
91
Well, just wondering how i can sort a small array of integers from smallest-largest and largest-smallest. Just tell me the basic idea, i can code it myself. All the program has to do is take in a set of integers into an array, insert, delete, calc average, mode, and median, i figured all of that out on my own, but sorting has me stumped.
 

kamper

Diamond Member
Mar 18, 2003
5,513
0
0
There would be two ways to go about it. The first is to write your own sorting algorithm. For a beginner this would typically be something like a buble sort or an insertion sort (do you know either of these?). The other is to use Collections.sort(). That will require you to put your numbers into a List which you may or may not know how to do at this point but it's definitely the less-work solution :)
 

OverVolt

Lifer
Aug 31, 2002
14,278
89
91
Thanks :p!

i googled bubble sorts, lots of helpful info there. Gave me the general idea of what i need to be doing, just need to intergrate into the program so that after i sort it doesn't throw off the ins/del/avg stuff. I'll try and see if i can make a quick menu and do a quick sort too.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
I could give you my "notfred" algorithm, but then again it takes an average of 40 seconds to sort 5 items.
 

agnitrate

Diamond Member
Jul 2, 2001
3,761
1
0
lol notfred, give him one of the most difficult sorting algorithms.

look at bubble sort and insertion sort. they are the easiest. order n^2, but the easiest.

-silver