0
Sorting an array in ascending order
I want to do a code where: -Only accepts up to 50 integers -Sentinel value of 0 (zero) -Only accepts positive numbers (And ignores negative numbers) -Sorts the inputted numbers into ascending order. I use eclipse as my compiler. but when I run my code nothing appears. This is my code: https://code.sololearn.com/cxhIFj1f4J6Z
11 Respostas
+ 2
Martin Taylor
Now you can check and tell me if still there is some issues, I have resolved all problem.
My input example is like this:
3
-12 11 10
4
1 3 2 7
5
1 -2 3 4 5
0 //exit value
+ 1
You algorithm for ordering of the array items do not work.
A easier algorithm is to set „tem“ with the first array item and thing it is bigest. And then check another etc. You can see a few sorting algorithms samples here:
https://www.sololearn.com/learn/774/
+ 1
Eka
2 mistakes:
1 - You are closing scanner object 'input' inside loop which will give exception
2 - there should be temp = num[k] instead of temp = num[i]
So here is solution, I have created different methods for different operations.
https://code.sololearn.com/cTa6XLUuvIRu/?ref=app
+ 1
Martin Taylor
Can you tell me when it is coming because I had entered input like this:
3 //no of elements
4
5
6
0 //to break do while loop
And it worked fine without any exception
And worked well on this inputs too:
5 4 -13 3 2 1 -12 0
+ 1
Martin Taylor
Yes I got that exception when we enter less number of elements.
Now please can you check?