Array with at most n duplicates
Hey all this is my first post on cprogramming.com as I am fairly new at C++.
I am taking a programming class and we were given an assignment that I am having trouble with.
1. The object of the assignment is to have an array of size n of random integers between x- z. (I have this part)
2. I am to create a new (dynamically allocated) array from the original with at most n duplicate values WITHOUT SORTING FIRST. (this is the part I am having trouble with)
I have tried moving the unwanted duplicates to the end and then ignoring them but I couldn't make it work.
I have tried using a temporary array of flags where unwanted duplicates are flagged as zero but couldn't make that work either.
I am having a real problem with the logic of this assignment.
I could really use a good algorithm in pseudocode for dynamically creating the second array with at most n duplicates.
Million thanks in advance,
kratz