-
Notifications
You must be signed in to change notification settings - Fork 5
/
search.h
81 lines (63 loc) · 1.76 KB
/
search.h
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
/*
This is search.h
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#ifndef SEARCH_H /* guard against multiple inclusions */
#define SEARCH_H
#include "globals.h"
#include "list.h"
namespace search {
using namespace coxeter;
using namespace list;
/******** type declarations *************************************************/
template <class T>
class BinaryTree;
template <class T>
struct TreeNode;
/******** function declarations *********************************************/
template <class T>
void print(FILE* file, const BinaryTree<T>& t);
template <class T>
void print(FILE*, TreeNode<T>*, const char*);
/******** type definitions **************************************************/
template <class T>
struct TreeNode {
TreeNode* left;
TreeNode* right;
T data;
/* constructors and destructors */
void* operator new(size_t size) {return arena().alloc(size);}
void operator delete(void* ptr)
{return arena().free(ptr,sizeof(TreeNode));}
TreeNode(const T& a);
~TreeNode();
};
template <class T>
class BinaryTree {
protected:
Ulong d_size;
TreeNode<T>* d_root;
public:
/* constructors and destructors */
void* operator new(size_t size) {return arena().alloc(size);}
void operator delete(void* ptr)
{return arena().free(ptr,sizeof(BinaryTree));}
BinaryTree();
virtual ~BinaryTree();
/* accessors */
Ulong size() const;
TreeNode<T>* root() const;
/* modifiers */
T* find(const T& a);
};
/******** inline definitions ************************************************/
template <class T>
inline Ulong BinaryTree<T>::size() const
{return d_size;}
template <class T>
inline TreeNode<T>* BinaryTree<T>::root() const
{return d_root;}
}
#include "search.hpp"
#endif