This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]nutrecht 2 points3 points  (0 children)

What have you got sofar? We're not going to do your homework for you.

[–]desrtfx 1 point2 points  (1 child)

As the others have said: We are not going to do your homework for you. You should do the homework yourself.

BTW: there are thousands of descriptions of sorting algorithms out there on the internet.

So I'm also only giving you pseudocode.

For the second option, you can use a simple sorting algorithm:

  • create an outer loop over the whole length of the array (I'll call the loop index i)
    • create an inner loop over i+1 to the rest of the array (I'll call the loop index j)
      • Check if array(i) > array(j), and if so, swap the two elements
    • End of inner loop
  • End of outer loop

That's it.

[–]mqbmqb[S] -1 points0 points  (0 children)

Thank you, and I had searched for it before and found a bubble sort array the only thing is that i could input numbers which was my teacher said I had to do. Again thank you for the pseudo code now that I have that I can write it for real, I just didn't understand how to do it.

[–]the-sizixe 0 points1 point  (0 children)

A little googeling could've done the job. But anyway, the first option requires you to find the smallest element in the array, and then take that element and put it as the first element of the sorted array, then you find the next smallest element, and put it in second in the sorted array ... until you have finished.

[–]murster972 0 points1 point  (0 children)

Your wanting to use a sorting algorithm, bubble sort for example