/* Create a function that takes an array of items, removes all * duplicate items and returns a new array in the same sequential * order as the old array (minus duplicates). */ #include // to use std::set #include // to use std::pair std::vector removeDups(std::vector arr) { std::vector newArr; std::set unique; for(int i=0;arr.size()>i;i++){ // insert will succeed if string is unique std::pair::iterator,bool> r = unique.insert(arr[i]); // unless insertion fails, add the string to newArr if (r.second) newArr.push_back(arr[i]); } return newArr; }