How to remove identical elements from array of integers

Nov 27, 2011 at 1:04pm
array is allocated dynamically., after that i want to re-size the array...
Nov 27, 2011 at 2:27pm
copying all the value of the array to the temporary array except the value which you want to delete and then copying all the values to the origanal array .
Nov 27, 2011 at 2:47pm
Removing identical Elements
it will probably work only for 1D array.
1. identify the element that needs to be deleted
2. copy all the remaining elements one step to the left
3. when the all the identical elements are overwritten make a new array of smaller size(depending how many elements were overwritten) and copy the old array to new array. again the index upto which the elements need to be copied depends upon how many elements were deleted.
Nov 27, 2011 at 2:54pm
You could use std::vector, rather than an array and std::sort() and std::unique(). Or you could just use a std::set from the outset.

std::vector
http://cplusplus.com/vector

std::sort()
http://cplusplus.com/set

std::unique()
http://cplusplus.com/reference/algorithm/unique/

std::set
http://cplusplus.com/set
Topic archived. No new replies allowed.