Tuesday 15 May 2012

C++ code not running as it should be -


Sorting algorithm is my C ++ code for counting, there is no error in it, there is no warning, But when I want to execute it is giving me this "Counting.exe has stopped working" I think this is a run time error

  zero count_source () { Int A [] = {5,15,20,30,40,8,36,25,96,15,40,15,96,47,20}; Int k = 15; Int n = 15; Int i, j; Intake [15]; Int c [100]; For (i = 0; i & lt; = k; i ++) c [i] = 0; For (J = 1; J & lt; = N; J ++) C [A] [J]] = C [A] [J] + 1; For (i = 1; i & lt; = k; i ++) c [i] = c [i] + c [i-1]; For (j = n; j & gt; = 1; j -) {b [c] [j]] = a [ja]; C [A] [J]] = C [A] [J] - 1; } Cout & lt; & Lt; "\ N Sorted array is:"; For (i = 1; i & lt; = n; i ++) COAT & LT; & Lt; B [i] & lt; & Lt; ""; } Zero main () {Counting_sort (); }  

 for  (j = n; j & gt; = 1 ; J -) {// you are reaching a [ja]}  

then a [15] is an invalid access and will lead to undefined behavior. . Valid access to the array is a [15] a [0] to a [14] except for any other limit .


No comments:

Post a Comment