0

I have an integer array of duplicated values

int array[] = {111, 111, 222, 333, 111, 444, 555, 111};

Out of the above array, I want to assign the unique values to the indexed vector array named vectorArray

Desired vectorArray values:

vectorArray[0] // 111
vectorArray[1] // 222
vectorArray[2] // 333
vectorArray[3] // 444
vectorArray[4] // 555

How would I go about it?

Sian
  • 21
  • 3
  • Many approaches come to mind.... is sorting the array an option? Or you could shove the values into a std::set, or you could put them into a std::unordered_set and get them back out. – AndyG Apr 10 '18 at 14:53
  • You would create an algo, write code and then make it work (debugging and testing) – Slava Apr 10 '18 at 14:53
  • @AndyG, thanks for your reply. I was not allowed to use std::set. I'm new to C++. If in php, it would have been easy: loop the array and index it's value to the vector. But C++ rings the "Out of range" bell – Sian Apr 10 '18 at 14:59

0 Answers0