So I am in a Java class in school, and I have a relatively simple assignment that I just can’t figure out. It’s not a problem to research the answer, so I am throwing it out to the brightest people out there. My simple java program takes 4 numbers as input, and then it is just supposed to spit those numbers right back out, but in order smallest to biggest. Anyone have any thoughts? I know there are probably lot of different ways to do this, but I am sure this can be done simply. My teacher for example, said that he can do it using only 6 non-nested or else-using if statements! I think he got into my head a little and so I am getting hung up. Any help out there would be greatly appreciated. Thanks
Share
Read up on bubble sort — an unrolled implementation of bubble sort would solve this problem with exactly 6 comparisons, and is probably what your teacher has in mind.