0
Getting junk number.
https://code.sololearn.com/cZkRZseLo0D1/?ref=app I am filing in random number into an array. Sorting should be before fill in it. However when I run my code. The first 20numbers are just junks Is my algorithms wrongs?
2 Respuestas
+ 1
Your algorithm may need some debugging, but you have another issue that may be making this harder to troubleshoot:
40: for (j=i; j>=0; j--)
41: {
42: if (num<arr[j-1])
43: {
44: arr[j]=arr[j-1];
The reason you're getting junk (it's actually the timestamp) is the answer to the question:
* What happens at lines 42 & 44 when j hits 0, at line 40?
Fix that, then you could try printing your values as you load them:
32: cout << "[" << num << "]";
This may help you track what's happening (how the initial values move).
0
but i wrote that if (i==0) goes into the arr[0]. else (.....rest of code). that i shouldnt be 0?