// Stephen Bassoli // CSE 124 Section 01 // Lab 7 #include template class BinTree; template class TreeNode { private: TreeNode *left; TreeNode *right; TreeNode *parent; T data; public: TreeNode(const T& item, TreeNode *lptr = NULL, TreeNode *rptr = NULL); // Input: None // Precond: None // Process: Constructor // Output: None // Postcond: None void ChangeData(const T& item); // Input: Data of item // Precond: None // Process: Changes nata of the node // Output: None // Postcond: None T& Data(void); // Input: None // Precond: None // Process: Returns data of the node // Output: Returns data of the node // Postcond: None TreeNode* Left(void); // Input: None // Precond: None // Process: None // Output: Returns node to the left // Postcond: None TreeNode* Right(void); // Input: None // Precond: None // Process: None // Output: Returns node to the right // Postcond: None TreeNode* Up(void); // Input: None // Precond: None // Process: None // Output: Returns the parent node // Postcond: None void SetLeft(TreeNode* lptr); // Input: Node to be set to the left // Precond: None // Process: Set node to the left // Output: None // Postcond: None void SetRight(TreeNode* rptr); // Input: Node to be set to the right // Precond: None // Process: Set node to the right // Output: None // Postcond: None void RemoveLeft(void); // Input: None // Precond: None // Process: Sets left to NULL // Output: None // Postcond: None void RemoveRight(void); // Input: None // Precond: None // Process: Sets right to NULL // Output: None // Postcond: None void RemoveSelfFromUp(void); // Input: None // Precond: None // Process: Removes self from parent // Output: None // Postcond: None bool LookLeft(void)const; // Input: None // Precond: None // Process: Sees if there is a node to the left // Output: Returns true if there is no node to the left // Postcond: None bool LookRight(void)const; // Input: None // Precond: None // Process: Sees if there is a node to the right // Output: Returns true if there is no node to the right // Postcond: None T& WhatLeft(void); // Input: None // Precond: None // Process: None // Output: Returns data of left // Postcond: None T& WhatRight(void); // Input: None // Precond: None // Process: None // Output: Returns data of right // Postcond: None T& WhatUp(void); // Input: None // Precond: None // Process: None // Output: Returns data of parent // Postcond: None }; template TreeNode::TreeNode(const T& item, TreeNode *lptr, TreeNode *rptr) { parent = NULL; left = lptr; right = rptr; data = item; } template void TreeNode::ChangeData(const T& item) { data = item; } template T& TreeNode::Data(void) { return data; } template TreeNode* TreeNode::Left(void) { if (left == NULL) return NULL; else return left; } template TreeNode* TreeNode::Right(void) { if (right == NULL) return NULL; else return right; } template TreeNode* TreeNode::Up(void) { if (parent == NULL) return NULL; else return parent; } template void TreeNode::SetLeft(TreeNode* lptr) { left = lptr; left->parent = this; } template void TreeNode::SetRight(TreeNode* rptr) { right = rptr; right->parent = this; } template void TreeNode::RemoveLeft(void) { left = NULL; } template void TreeNode::RemoveRight(void) { right = NULL; } template void TreeNode::RemoveSelfFromUp(void) { if (parent->Left() == this) parent->RemoveLeft(); else if (parent->Right() == this) parent->RemoveRight(); } template bool TreeNode::LookLeft(void)const { if (left == NULL) return true; else return false; } template bool TreeNode::LookRight(void)const { if (right == NULL) return true; else return false; } template T& TreeNode::WhatLeft(void) { return left->Data(); } template T& TreeNode::WhatRight(void) { return right->Data(); } template T& TreeNode::WhatUp(void) { return parent->Data(); }