1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
| #ifndef _myset #define _myset #include<iostream> #include<set> using namespace std;
template<class _ty,class _container = set<_ty>> class MySet { public:
typedef MySet<_ty, _container> _MySet;
MySet() :c() {
} ~MySet() {
} MySet(const _MySet& _Right) :c(_Right.c) {
} MySet(const _container* _Left) :c(_Left) {
} _MySet& operator=(const _MySet& _Right) { this->c = _Right.c; return *this; } bool insert(const _ty& _Val) { pair<typename _container::iterator, bool>ret = c.insert(_Val); if (ret.second) { cout << _Val << "插入成功" << endl; return true; } else { cout << _Val << "插入失败" << endl; return false; } }
bool empty()const { return c.empty; } bool erase(const _ty& _Val) { if (c.erase(_Val) > 0) { return true; } return false; } int size()const { return c.size(); } pair<_ty, bool> GetMax()const { pair<_ty, bool>ret; typename _container::iterator max = c.end(); if (c.size() > 0) { ret.first = *(--max); ret.second = true; return ret; } else { ret.second = false; return ret; } } pair<_ty, bool> GetMin()const { pair<_ty, bool>ret; typename _container::iterator min = c.begin(); if (min != c.end()) { ret.first = *c.begin(); ret.second = true; return ret; } else { ret.second = false; return ret; }
} void print()const { for (typename _container::iterator it = c.begin(); it != c.end(); it++) { cout << *it << " "; } cout << endl; }
protected: _container c; };
#endif
|