게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
[본삭금] c++ 이진탐색트리 구현 질문입니다.. ㅠㅠ
게시물ID : programmer_22936짧은주소 복사하기
작성자 : 안녕하세
추천 : 0
조회수 : 2471회
댓글수 : 2개
등록시간 : 2019/06/05 00:39:23
옵션
  • 본인삭제금지
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


74 75번째 줄에서 계속 오류가 발생하는데 어떻게 짜야되는건가요 ㅠㅠㅠ
 
C2825 'E': '::'가 뒤에 나오면 클래스 또는 네임스페이스여야 합니다.
C2510 'E': '::' 왼쪽은 클래스/구조체/공용 구조체이어야 합니다.
C3646 'K': 알 수 없는 재정의 지정자입니다.

C4430 형식 지정자가 없습니다. int로 가정합니다. 참고: C++에서는 기본 int를 지원하지 않습니다.

 

얘네가 계속 나오네요..ㅠㅠㅠ

전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호