class BinaryNode
1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: // Listing 16-2.
6: /** A class of nodes for a link-based binary tree.
7: @file BinaryNode.h */
8:
9: #ifndef BINARY_NODE_
10: #define BINARY_NODE_
11: #include <memory>
13: template<class ItemType>
14: class BinaryNode
15: {
16: private:
17: ItemType item; // Data portion
18: std::shared_ptr<BinaryNode<ItemType>> leftChildPtr; // Pointer to left child
19: std::shared_ptr<BinaryNode<ItemType>> rightChildPtr; // Pointer to right child
20:
21: public:
22: BinaryNode();
23: BinaryNode(const ItemType& anItem);
24: BinaryNode(const ItemType& anItem,
25: std::shared_ptr<BinaryNode<ItemType>> leftPtr,
26: std::shared_ptr<BinaryNode<ItemType>> rightPtr);
27:
28: void setItem(const ItemType& anItem);
29: ItemType getItem() const;
30:
31: bool isLeaf() const;
32:
33: auto getLeftChildPtr() const;
34: auto getRightChildPtr() const;
35:
36: void setLeftChildPtr(std::shared_ptr<BinaryNode<ItemType>> leftPtr);
37: void setRightChildPtr(std::shared_ptr<BinaryNode<ItemType>> rightPtr);
38: }; // end BinaryNode
40: #include "BinaryNode.cpp"
41: #endif