Arrrays

Jul 19, 2014 at 8:36am
Does anybody knows how to store 10 elements in an array and delete the duplicate terms ? ( its a single dimension array )
Last edited on Jul 19, 2014 at 8:37am
Jul 19, 2014 at 9:19am
look into <algorithm>
Jul 19, 2014 at 10:23am
@OP
Do you mean delete consecutive duplicate terms or duplicate terms anywhere in the array?

For the former case you can use std::unique in the algorithm header.

For the latter, you will either have to first sort the array using std::sort and then use std::unique or develop an algorithm of your own.
Jul 19, 2014 at 11:57am
oh ok thanks,actually i meant if we taking both the cases where the inputted duplicate terms can be consecutive as well as in random order and then it can be printed without the duplicate numbers.
Jul 19, 2014 at 11:58am
can you send the algorithm if possible ?
Jul 19, 2014 at 4:23pm
actually i meant if we taking both the cases where the inputted duplicate terms can be consecutive as well as in random order


That is the second case which refers to "duplicate terms anywhere in the array." Note that anywhere includes the possibility of "next to" or "consecutive."

How would you do it on paper?
Topic archived. No new replies allowed.