Can someone immediately help correcting the mistake i made? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can someone immediately help correcting the mistake i made?

i am trying to sort an array of integers and putting in another array in a very simple and old fashioned way. but when I'm trying to print the outputs, its showing only 0s. can someone please show me what I'm missing? thanks in advance. Full code URL- http://paste.ubuntu.com/23664859/ (Title- Plain Sorting with Loops) (please don't mind my coding style... :p )

21st Dec 2016, 5:25 PM
archimidis
3 Answers
+ 1
I don't bring the solution, but I can say the mistake is in your sort function : before the sort, if you print your first array ( unsorted ) it's valid, but if you print it after, he's full of 0s ^^ I suggest you to rewrite your sort function with more line, and to test the differents values by putting debug printing instruction to differents places... [ edit ] You didn't have precise your code is C# ( I first think it was java :( )
21st Dec 2016, 6:02 PM
visph
visph - avatar
0
Is this supposed to be a certain sort algorithm? Can you explain the idea? As visph said, the problem is the sorting process itself and I don't really get what you're trying to do. What I can already say now is that your for loops probably shouldn't look at the n-th element when sorting because this should be 0. So simply use i<n and j<n, respectively. Regards, Alex
21st Dec 2016, 7:24 PM
alex189
0
to Visph, thanks very much for your response. I'll work on it as u suggested. and I am extremely sorry for not being able to ask the question very understandably. to Alex, the idea is just to take some random integers in an array and store the sorted version in another array. its not planned according to any particular algorithm. i just coded as simple as i can think. at the moment I am not able to test your suggestion. but I'll reply whenever i do. thanks very much for the idea.
22nd Dec 2016, 10:02 AM
archimidis