Node* nodePtr = head; // assuming head is a pointer to the first node of a linked list while (nodePtr != nullptr) { std::cout << nodePtr->getData() << " "; nodePtr = nodePtr->getNext(); }
int findMax(Node* node) { if (node == nullptr) return INT_MIN; int max = node->getData(); int leftMax = findMax(node->getLeft()); int rightMax = findMax(node->getRight()); if (leftMax > max) max = leftMax; if (rightMax > max) max = rightMax; return max; }This example uses Node::getLeft(), Node::getRight() methods to traverse a binary search tree and Node::getData() to get the value of each node. Package library: There are various package libraries that provide binary search tree data structures in C++, such as STL (Standard Template Library), Boost, and Eigen.