There is an array which consists of n integers . we have to delete items which are equal . First equal item is declared . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

There is an array which consists of n integers . we have to delete items which are equal . First equal item is declared .

for example : int Parray [6] = {1 , 2 , 1 , 1, 5 , 6}; result is { 1 , 2 , 5 , 6 } ( I'm sorry if it's complicated , my English isn't so good )

18th Mar 2018, 10:22 AM
Jakhongir
Jakhongir - avatar
1 Answer
+ 3
void unify(int arr[], int& size) { set<int> s; for(int i=0;i<size;i++) s.insert(arr[i]); size=s.size(); copy(arr,arr+size,s.begin()); } That removes any duplicates inside your array.
18th Mar 2018, 10:59 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar