Home > Back-end >  Would you please tell me why DevC debugging and running the output does not agree?
Would you please tell me why DevC debugging and running the output does not agree?

Time:11-03

My input:

7

0, 1, 4, 5 3 2 6

After a try, I won't be found debugging to check the list add any view variables, the output is correct: 0 1 2 3 4 5 6

Added view variables, output results such as random, every time to open the file
debugging output results are different
And I want to see an array variable element, add a view variables: * (& amp; A [0]) @ 10 and * (& amp; T [0]) @ 10

Later found what view variables don't add debugging, debugging output is right

Good depressed ah, is this why?
 # include & lt; Cstdio> 
#include
#include
Int t [100005];
Int a, [100005].
Int n;
Void mergeSort (int int l, r) {//* sorts [l, r]
If (l==r) return;
Int mid=(l + r)/2;
MergeSort (l, mid);//sorting a/l, mid
MergeSort (mids + 1, r);//sorting a [mid + 1, r]
Int p=l, q=mid + 1, I=l;//merge to the t/l, r
While (p<=mid & amp; & Q<=r) {//two team can take
If (a [p] <[q] a)
T=[i++] a [p++];
The else
T=[i++] a [q++];
}
While (p & lt;=a=mid) t [i++] [p++];//the team didn't take
While (q & lt;=a=r) t [i++] [q++];//on the right side of the team didn't take
For (int I=l; i<=r; I++) [I] a [I]=t;
}

Void inp () {
The scanf (" % d ", & amp; n);
for(int i=1; i<=n; I++) the scanf (" % d ", & amp; A [I]);
}

Int main (void) {
Inp ();
MergeSort (1, n);
for(int i=1; i<=n; I++) printf (" % d ", a [I]);
Puts (" ");
return 0;
}

CodePudding user response:

And I think to 21 done for memcpy (a, t, sizeof (a))
Run the output is also wrong
Really doubt QAQ for bosses to reassure

CodePudding user response:


Q=3
Mid + 1=2
Debugging is the problem here, I clearly has q=mid + 1
  • Related