Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <iterator>
- #include <string>
- #include <vector>
- #include <list>
- #include <deque>
- #include <set>
- using namespace std;
- template<typename Container>
- typename Container::iterator returnLastRepeat(Container &cont)
- {
- typename Container::iterator ans = cont.end();
- for (typename Container::iterator it1 = cont.begin(); it1 != cont.end(); it1++)
- {
- for (typename Container::iterator it2 = cont.begin(); it2 != it1; it2++)
- {
- if (*it1 == *it2) ans = it1;
- }
- }
- return ans;
- }
- int main()
- {
- int arr1[10] = {1, 2, 3, 4, 4, 5, 6, 6, 7, 8};
- vector<int> cont1 (arr1, arr1 + 10);
- cout << "Last repeating element in vector: " << (*returnLastRepeat(cont1)) << endl;
- double arr2[5] = {1.3, 5.7, 9.4, 5.7, 10.3};
- list<double> cont2 (arr2, arr2 + 5);
- cout << "Last repeating element in list: " << *returnLastRepeat(cont2) << endl;
- string arr3[8] = {"one", "two", "three", "four", "three", "two", "one", "ten"};
- set<string> cont3 (arr3, arr3 + 8);
- if (returnLastRepeat(cont3)==cont3.end()) cout << "GOOD\n";
- else cout << "Last repeating element in set: " << *returnLastRepeat(cont3) << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment