Created
December 15, 2021 14:57
-
-
Save ahmedtalaat327/878824ec6c7a967c8723329d73f58ac5 to your computer and use it in GitHub Desktop.
Removing duplicates in a vector of strings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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