Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <cstring>
- template <typename T, typename D>
- class Biection <T, D>{
- public:
- D getPairX(T x);
- T getPairY(D y);
- void add(T x, D y);
- private:
- std::map <T, D> _map;
- };
- template <typename T, typename D>
- D Biection::getPairX(T x) {
- std::map::iterator it = _map.find(x);
- if(it != _map.end())
- return it->second;
- else{
- std::string str = "Element not found!";
- throw str;
- }
- }
- template <typename T, typename D>
- T Biection::getPairY(D y) {
- for(std::map::iterator it = _map.begin(); it != _map.end(); ++it){
- if(it->second == y)
- return it->first;
- }
- std::string str = "Element not found!";
- throw str;
- }
- template <typename T, typename D>
- void Biection::add(T x, D y) {
- try {
- getPairX(x);
- }catch (std::string e){
- try{
- getPairY(y);
- }catch (std::string e){
- _map.insert(std::pair(x, y));
- return;
- }
- }
- std::string str = "This biection already exists!";
- throw str;
- }
- int main() {
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement