c++ - Dealloc core dump -
i have problem implementation of counting sort.
i have traced error delete [] c gives me core dump during execution. if remove delete program works normally. what's reason of this? can't explain caused by. post below main , counting_sort functions. there other functions create random numbers , stamp.
void counting_sort (int *a, int n, int k) { int *b = new int [k]; //array b's inizialization (int i=0; i<k; i++) b[i] = 0; //presence counter in array "a" (int i=0; i<n; i++) b[a[i]]++; //b's element sum (int i=0; i<k-1; i++) b[i+1] += b[i]; int *c = new int [n]; //final sort (int i=0; i<n; i++) { c[b[a[i]]] = a[i]; b[a[i]]--; } delete [] b; //coping c's elements (int i=0; i<n; i++) a[i] = c[i]; **delete [] c**; } int main() { cout<<"type array size: "; int n; cin>>n; int *a = new int [n]; cout<<"type maximum value array contain: "; int k; cin>>k; random_n(a,n,k); stamp(a,n); counting_sort(a,n,k+1); stamp(a,n); delete [] a; return 0; }
Comments
Post a Comment