void sort_int_array(int A[], int n) {
int i, j, h, k, O[n];
/* assume that A[0] to A[n-1] have valid values */
for (i=1; i<n; i++) {
/* swap A[i] left into correct position */
for (j=i-1; j>=0 && A[j+1] <= A[j]; j--) {
int_swap(&A[j], &A[j+1]);
for (k=0; k<n; k++) {
for (h = 0; h < k; h++) {
if (A[k] == O[h]) {
break;
}
else {
O[k] = A[k];
}
}
}
}
}
}
I'm attempting to only write distinct values from a sorted array to another array. The first part of the function sorts the array however when I write it to my new array it returns the sorted array and doesn't remove the copies.
eg. Input: 4 5 6 7 6 5 4. Output: 4 4 5 5 6 6 7.
Output wanted: 4 5 6 7