-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBinaryNode.cpp
More file actions
134 lines (109 loc) · 3.73 KB
/
BinaryNode.cpp
File metadata and controls
134 lines (109 loc) · 3.73 KB
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
// Created by Frank M. Carrano and Tim Henry.
// Copyright (c) 2013 __Pearson Education__.
// Modified by Ioannis Stamos and Yosef Yudborovsky
#ifndef TEACH_CSCI235_BST_BINARY_NODE_CPP
#define TEACH_CSCI235_BST_BINARY_NODE_CPP
#include "BinaryNode.h"
#include <cstddef>
#include <list>
#include <iostream>
using namespace std;
template<class ItemType, class OtherType>
BinaryNode<ItemType, OtherType>::BinaryNode() : item_(ItemType()), other_(OtherType()), left_ptr_(NULL), right_ptr_(NULL)
{
} // end default constructor
template<class ItemType, class OtherType>
BinaryNode<ItemType, OtherType>::BinaryNode(const ItemType& an_item) : item_(an_item), other_(OtherType()), left_ptr_(NULL), right_ptr_(NULL)
{
} // end constructor
/*template<class ItemType, class OtherType>
BinaryNode<ItemType, OtherType>::BinaryNode(const ItemType& an_item, const ItemType& other_) : left_ptr_(NULL), right_ptr_(NULL)
{
item = an_item;
other = other_;
} // end constructor*/
// template<class ItemType>
// BinaryNode<ItemType>::BinaryNode(const ItemType& anItem, BinaryNode<ItemType>* leftPtr,
// BinaryNode<ItemType>* rightPtr) : item(anItem), left_ptr_(leftPtr), right_ptr_(rightPtr)
// {
// } // end constructor
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::SetItem(const ItemType& an_item)
{
item_ = an_item;
} // end setItem
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::SetOther(const OtherType& other) // (const OtherType& other)
{
other_ = other;
} // end setItem
template<class ItemType, class OtherType>
ItemType BinaryNode<ItemType, OtherType>::GetItem() const
{
return item_;
} // end getItem
template<class ItemType, class OtherType>
OtherType BinaryNode<ItemType, OtherType>::GetOther() const
{
return other_;
}
template<class ItemType, class OtherType>
OtherType &BinaryNode<ItemType, OtherType>::GetOtherReference()
{
return other_;
}
template<class ItemType, class OtherType>
bool BinaryNode<ItemType, OtherType>::IsLeaf() const
{
return ((left_ptr_ == NULL) && (right_ptr_ == NULL));
}
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::SetLeftPtr(BinaryNode<ItemType, OtherType>* left_ptr)
{
left_ptr_ = left_ptr;
} // end setLeftChildPtr
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::SetRightPtr(BinaryNode<ItemType, OtherType>* right_ptr)
{
right_ptr_ = right_ptr;
} // end setRightChildPtr
template<class ItemType, class OtherType>
BinaryNode<ItemType, OtherType>* BinaryNode<ItemType, OtherType>::GetLeftPtr() const
{
return left_ptr_;
} // end getLeftChildPtr
template<class ItemType, class OtherType>
BinaryNode<ItemType, OtherType>* BinaryNode<ItemType, OtherType>::GetRightPtr() const
{
return right_ptr_;
} // end getRightChildPtr
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::addLine(int lineNum) // Adds line number to other
{
//int lineNum = lineNumber;
try {
other_.push_back (lineNum);
} catch (int num) {
//other_.push (lineNum);
}
}
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::displayLines() // Display line numbers from the list
{
cout << " Lines: ";
for(int i=0; i<other_.size();i++)
{
int x = (other_.front()+1);
cout << " " << x << ", ";
other_.pop_front();
other_.push_back(x);
}
}
template<class ItemType, class OtherType>
void BinaryNode<ItemType, OtherType>::displayWordCount() // Adds line number to other
{
cout << "Count: " << other_.size() << " ";
//if (binaryTree->maxSize < other_.size())
//other_.pop_front();
}
#endif // #define TEACH_CSCI235_BST_BINARY_NODE_CPP