Binary Search Tree (C++)
Loading...
Searching...
No Matches
Node Class Reference

Represents a node within a binary search tree. More...

#include <Node.h>

Public Member Functions

 Node (int value)
 Constructs a Node with the specified integer value.
int getValue () const
 Returns the stored integer value.
void setValue (int value)
 Sets the stored integer value.
NodegetLeft () const
 Returns a pointer to the left child node.
void setLeft (Node *left)
 Sets the pointer to the left child node.
NodegetRight () const
 Returns a pointer to the right child node.
void setRight (Node *right)
 Sets the pointer to the right child node.

Detailed Description

Represents a node within a binary search tree.

The Node class represents the fundamental unit of an iterative, pointer-based binary search tree. Each node maintains self-referential raw pointers to its left and right child nodes and stores a single integer data value.

Encapsulation is enforced through data hiding. All data members are declared as private and may only be accessed or modified through public accessor methods.

Definition at line 35 of file Node.h.

Constructor & Destructor Documentation

◆ Node()

Node::Node ( int v)

Constructs a Node with the specified integer value.

Parameters
valueThe integer value stored in the node.

Constructs a node initialized with the specified value and null child pointers.

Definition at line 20 of file Node.cpp.

20: value(v), left(nullptr), right(nullptr) {}

Member Function Documentation

◆ getLeft()

Node * Node::getLeft ( ) const

Returns a pointer to the left child node.

Returns
Pointer to the left child, or nullptr if none exists.

Fetches the left child pointer; returns nullptr if there is no left child.

Definition at line 39 of file Node.cpp.

39 {
40 return left;
41}

◆ getRight()

Node * Node::getRight ( ) const

Returns a pointer to the right child node.

Returns
Pointer to the right child, or nullptr if none exists.

Fetches the right child pointer; returns nullptr if there is no right child.

Definition at line 52 of file Node.cpp.

52 {
53 return right;
54}

◆ getValue()

int Node::getValue ( ) const

Returns the stored integer value.

Retrieves the node's stored integer value.

Definition at line 25 of file Node.cpp.

25 {
26 return value;
27}

◆ setLeft()

void Node::setLeft ( Node * l)

Sets the pointer to the left child node.

Parameters
leftPointer to the node to be assigned as the left child.
Note
Ownership of the node is not transferred.

Assigns the left child pointer.

Definition at line 46 of file Node.cpp.

46 {
47 left = l;
48}

◆ setRight()

void Node::setRight ( Node * r)

Sets the pointer to the right child node.

Parameters
rightPointer to the node to be assigned as the right child.
Note
Ownership of the node is not transferred.

Assigns the right child pointer.

Definition at line 59 of file Node.cpp.

59 {
60 right = r;
61}

◆ setValue()

void Node::setValue ( int v)

Sets the stored integer value.

Parameters
valueThe new integer value to store.

Assigns a new integer value to the node.

Definition at line 32 of file Node.cpp.

32 {
33 value = v;
34}

The documentation for this class was generated from the following files: