옵션 |
|
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 | // Entry.h #include <iostream> using namespace std; template <typename K, typename V> class Entry { public: typedef K Key; typedef V Value; public: Entry(const K& k= K(), const V& v=V()) :_key(k), _value(v) {} K& key() { return _key; } V& value() { return _value; } void setKey(const K& k) { _key = k; } void setValue(const V& v) { _value = v; } private: K _key; V _value; }; //LinkedBinaryTree.h #include <list> #include "Entry.h" typedef int Elem; class LinkedBinaryTree { public: struct Node { Entry<Elem, Elem> E; Node* par; Node* left; Node* right; Node() : par(NULL), left(NULL), right(NULL) {} }; public: class Position { private: Node* v; public: Position(Node* _v=NULL) : v(_v) {} Elem& operator*() { return v->E.value(); } Position left() const { return Position(v->left); } Position right() const { return Position(v->right); } Position parent() const { return Position(v->par); } bool isRoot() const { return v->par == NULL; } bool isExternal() const { return v->left == NULL && v->right == NULL; } bool isInternal() const { return v->left != NULL || v->right != NULL; } //추가 friend class LinkedBinaryTree; }; typedef std::list<Position> PositionList; public: LinkedBinaryTree(); int size() const; bool empty() const; Position root() const; PositionList positions() const; void addRoot(); void expandExternal(const Position& p); Position removeAboveExternal(const Position& p); protected: void preorder(Node* v, PositionList& pl) const; private: Node* _root; int n; }; //SearchTree.h #include "LinkedBinaryTree.h" template <typename E> class SearchTree { public: typedef typename E::Key K; typedef typename E::Value V; class Iterator; public: SearchTree(); int size(); bool empty() const; Iterator find(const K& k); Iterator insert(const K& k, const V& x); void erase(const K& k); void erase(const Iterator& p); Iterator begin(); Iterator end(); protected: //typedef LinkedBinaryTree<E> BinaryTree; typedef typename LinkedBinaryTree::Position TPos; TPos root() const; TPos finder(const K& k, const TPos& v); TPos inserter(const K& k, const V& x); TPos eraser(TPos& v); //TPos restructe(const TPos& v); private: LinkedBinaryTree T; int n; public: class Iterator { private: TPos v; public: Iterator(const TPos& vv) : v(vv) {} const E& operator*() const { return *v; } const E& operator*() { return *v; } bool operator==(const Iterator& p) const { return v == p.v; } Iterator& operator++(); friend class SearchTree; }; }; | cs |
C4430 형식 지정자가 없습니다. int로 가정합니다. 참고: C++에서는 기본 int를 지원하지 않습니다.
얘네가 계속 나오네요..ㅠㅠㅠ