remove duplicates from an array

I'd like to make a void function that merge two arrays and delete duplicates then return the size of the array.

below is to merge two arrays. n1+n2 are less than 1000 for sure so I set result[1000]
1
2
3
4
5
6
7
8
9
10
11
12
13
	size_t k = 0;
	size_t i = 0;
	while (i < n1) {
		result[k] = arr1[i];
		k++;
		i++;
	}
	while (i < n2) {
		k = n1;
		result[k] = arr2[i];
		k++;
		i++;
	}


and I wrote a code that checks if two elements are duplicates as below
1
2
3
4
5
6
		for (size_t i=0; i < n; i++) {
			for (size_t k = 0; k < n; k++) {
				if (i!=k && array[i] == array[k]) ///???????????

			}
		}


I'm stuck here because I don't know how to remove the element from the array :( Can anybody give me wisdom. and I'd so appreciate if you glance at the merging arrays code if it's right
Check this good program how to remove duplicates from an array, it's in C but you should be able to C++ it:
http://www.codeforwin.in/2015/07/c-program-to-delete-duplicate-elements-from-array.html
In your code, you aren't copying the first n1 items of arr2.

I always find it helpful to think in terms of the source and destination (src & dst). In this case, they would be indexes:
1
2
3
4
5
6
7
8
int src,dst;
for (src=0; src<n1; ++src) {
    result[src] = arr1[src];
}
dst=src;
for (src=0; src<n2; ++src, ++dst) {
    result[dst] = arr1[src];
}

Are these arrays sorted? That would make it easier to check for duplicates. Should the result be sorted?
Topic archived. No new replies allowed.