Need help with the TODO's (DONE IN C++)
#pragma once
#include <functional> // std::less
#include <iostream>
#include <queue> // std::queue
#include <utility> // std::pair
template <typename K, typename V, typename Comparator = std::less<K>>
class BinarySearchTree
{
public:
using key_type = K;
using value_type = V;
using key_compare = Comparator;
using pair = std::pair<key_type, value_type>;
using pointer = pair*;
using const_pointer = const pair*;
using reference = pair&;
using const_reference = const pair&;
using difference_type = ptrdiff_t;
using size_type = size_t;
private:
struct BinaryNode
{
pair element;
BinaryNode *left;
BinaryNode *right;
BinaryNode( const_reference theElement, BinaryNode *lt, BinaryNode *rt )
: element{ theElement }, left{ lt }, right{ rt } { }
BinaryNode( pair && theElement, BinaryNode *lt, BinaryNode *rt )
: element{ std::move( theElement ) }, left{ lt }, right{ rt } { }
};
using node = BinaryNode;
using node_ptr = node*;
using const_node_ptr = const node*;
node_ptr _root;
size_type _size;
key_compare comp;
public:
BinarySearchTree() {
// TODO
}
BinarySearchTree( const BinarySearchTree & rhs ) {
// TODO
}
BinarySearchTree( BinarySearchTree && rhs ) {
// TODO
}
~BinarySearchTree() {
// TODO
}
const_reference min() const { return min( _root )->element; }
const_reference max() const { return max( _root )->element; }
const_reference root() const {
// TODO
}
bool contains( const key_type & x ) const { return contains( x, _root ); }
value_type & find( const key_type & key ) { return find( key, _root )->element.second; }
const value_type & find( const key_type & key ) const { return find( key, _root )-
>element.second; }
bool empty() const {
// TODO
}
size_type size() const {
// TODO
}
void clear() {
clear( _root );
_size = 0;
}
void insert( const_reference x ) { insert( x, _root ); }
void insert( pair && x ) { insert( std::move( x ), _root ); }
void erase( const key_type & x ) { erase(x, _root); }
BinarySearchTree & operator=( const BinarySearchTree & rhs ) {
// TODO
}
BinarySearchTree & operator=( BinarySearchTree && rhs ) {
// TODO
}
private:
void insert( const_reference x, node_ptr & t ) {
// TODO
}
void insert( pair && x, node_ptr & t ) {
// TODO
}
void erase( const key_type & x, node_ptr & t ) {
// TODO
}
const_node_ptr min( const_node_ptr t ) const {
// TODO
}
const_node_ptr max( const_node_ptr t ) const {
// TODO
}
bool contains( const key_type & x, const_node_ptr t ) const {
// TODO
}
node_ptr find( const key_type & key, node_ptr t ) {
// TODO
}
const_node_ptr find( const key_type & key, const_node_ptr t ) const {
// TODO
}
void clear( node_ptr & t ) {
// TODO
}
node_ptr clone ( const_node_ptr t ) const {
// TODO
}
public:
template <typename KK, typename VV, typename CC>
friend void printLevelByLevel( const BinarySearchTree<KK, VV, CC>& bst, std::ostream & out
);
template <typename KK, typename VV, typename CC>
friend std::ostream& printNode(std::ostream& o, const typename BinarySearchTree<KK, VV,
CC>::node& bn);.Read less