Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ahmedtalaat327/878824ec6c7a967c8723329d73f58ac5 to your computer and use it in GitHub Desktop.

Select an option

Save ahmedtalaat327/878824ec6c7a967c8723329d73f58ac5 to your computer and use it in GitHub Desktop.
Removing duplicates in a vector of strings.
// Online C++ compiler to run C++ program online
#include <iostream>
#include <string>
#include <vector>
#include <set>
using namespace std;
class QueueHandler{
public:
QueueHandler(vector<string> coming){
_in=coming;
}
vector<string> removeReplicated(void){
vector<string> out;
set<string> const uniques(_in.begin(), _in.end());
_in.assign(uniques.begin(), uniques.end());
out=_in;
return out;
}
private:
vector<string> _in;
};
int main() {
vector<string> sample_before =
{"ahmed", "yahia","tamer","yahia","ahmed","abdo"};
for(auto &it : sample_before){
cout << it+"\n";
}
cout << "--------------\n";
QueueHandler qu_handle{sample_before};
auto sample_after = qu_handle.removeReplicated();
for(auto &it : sample_after){
cout << it+"\n";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment