SlideShare a Scribd company logo
1 of 10
Download to read offline
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);
template <typename KK, typename VV, typename CC>
friend void printTree( const BinarySearchTree<KK, VV, CC>& bst, std::ostream & out );
template <typename KK, typename VV, typename CC>
friend void printTree(typename BinarySearchTree<KK, VV, CC>::const_node_ptr t,
std::ostream & out, unsigned depth );
template <typename KK, typename VV, typename CC>
friend void vizTree(
typename BinarySearchTree<KK, VV, CC>::const_node_ptr node,
std::ostream & out,
typename BinarySearchTree<KK, VV, CC>::const_node_ptr prev
);
template <typename KK, typename VV, typename CC>
friend void vizTree(
const BinarySearchTree<KK, VV, CC> & bst,
std::ostream & out
);
};
template <typename KK, typename VV, typename CC>
std::ostream& printNode(std::ostream & o, const typename BinarySearchTree<KK, VV,
CC>::node & bn) {
return o << '(' << bn.element.first << ", " << bn.element.second << ')';
}
template <typename KK, typename VV, typename CC>
void printLevelByLevel( const BinarySearchTree<KK, VV, CC>& bst, std::ostream & out =
std::cout ) {
using node = typename BinarySearchTree<KK, VV, CC>::node;
using node_ptr = typename BinarySearchTree<KK, VV, CC>::node_ptr;
using const_node_ptr = typename BinarySearchTree<KK, VV, CC>::const_node_ptr;
// TODO -- Guide in Instructions
}
template <typename KK, typename VV, typename CC>
void printTree( const BinarySearchTree<KK, VV, CC> & bst, std::ostream & out = std::cout ) {
printTree<KK, VV, CC>(bst._root, out ); }
template <typename KK, typename VV, typename CC>
void printTree(typename BinarySearchTree<KK, VV, CC>::const_node_ptr t, std::ostream &
out, unsigned depth = 0 ) {
if (t != nullptr) {
printTree<KK, VV, CC>(t->right, out, depth + 1);
for (unsigned i = 0; i < depth; ++i)
out << 't';
printNode<KK, VV, CC>(out, *t) << 'n';
printTree<KK, VV, CC>(t->left, out, depth + 1);
}
}
template <typename KK, typename VV, typename CC>
void vizTree(
typename BinarySearchTree<KK, VV, CC>::const_node_ptr node,
std::ostream & out,
typename BinarySearchTree<KK, VV, CC>::const_node_ptr prev = nullptr
) {
if(node) {
std::hash<KK> khash{};
out << "t" "node_" << (uint32_t) khash(node->element.first)
<< "[label="" << node->element.first
<< " [" << node->element.second << "]"];" << std::endl;
if(prev)
out << "tnode_" << (uint32_t) khash(prev->element.first) << " -> ";
else
out << "t";
out << "node_" << (uint32_t) khash(node->element.first) << ";" << std::endl;
vizTree<KK, VV, CC>(node->left, out, node);
vizTree<KK, VV, CC>(node->right, out, node);
}
}
template <typename KK, typename VV, typename CC>
void vizTree(
const BinarySearchTree<KK, VV, CC> & bst,
std::ostream & out = std::cout
) {
out << "digraph Tree {" << std::endl;
vizTree<KK, VV, CC>(bst._root, out);
out << "}" << std::endl;
}

More Related Content

Similar to Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf

Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfindiaartz
 
In c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdfIn c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdfrajkumarm401
 
Aho-Corasick string matching algorithm
Aho-Corasick string matching algorithmAho-Corasick string matching algorithm
Aho-Corasick string matching algorithmTakatoshi Kondo
 
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdfPlease code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdffarankureshi
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methodsphil_nash
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdfadityastores21
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxbraycarissa250
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたAkira Maruoka
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfsupport58
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfkostikjaylonshaewe47
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6rohassanie
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxShashiShash2
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3ecomputernotes
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfezzi552
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfSANDEEPARIHANT
 

Similar to Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf (20)

Add these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdfAdd these three functions to the class binaryTreeType (provided).W.pdf
Add these three functions to the class binaryTreeType (provided).W.pdf
 
In c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdfIn c++ format, for each function in the code, please using the comme.pdf
In c++ format, for each function in the code, please using the comme.pdf
 
Aho-Corasick string matching algorithm
Aho-Corasick string matching algorithmAho-Corasick string matching algorithm
Aho-Corasick string matching algorithm
 
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdfPlease code in C++ and do only the �TO DO�s and all of them. There a.pdf
Please code in C++ and do only the �TO DO�s and all of them. There a.pdf
 
C++ extension methods
C++ extension methodsC++ extension methods
C++ extension methods
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
 
The Future of C++
The Future of C++The Future of C++
The Future of C++
 
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docxAssignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
Assignment 13assg-13.cppAssignment 13assg-13.cpp   @auth.docx
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
Chainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみたChainer-Compiler 動かしてみた
Chainer-Compiler 動かしてみた
 
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdfPlease complete ALL of the �TO DO�s in this code. I am really strugg.pdf
Please complete ALL of the �TO DO�s in this code. I am really strugg.pdf
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
FP 201 - Unit 6
FP 201 - Unit 6FP 201 - Unit 6
FP 201 - Unit 6
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
C++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptxC++ FUNCTIONS-1.pptx
C++ FUNCTIONS-1.pptx
 
computer notes - Data Structures - 3
computer notes - Data Structures - 3computer notes - Data Structures - 3
computer notes - Data Structures - 3
 
Antlr V3
Antlr V3Antlr V3
Antlr V3
 
I have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdfI have the following code and I need to know why I am receiving the .pdf
I have the following code and I need to know why I am receiving the .pdf
 
Write a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdfWrite a C program that reads the words the user types at the command.pdf
Write a C program that reads the words the user types at the command.pdf
 

More from actexerode

Number of years to provide a given return In the information given in.pdf
Number of years to provide a given return In the information given in.pdfNumber of years to provide a given return In the information given in.pdf
Number of years to provide a given return In the information given in.pdfactexerode
 
Number of years needed to accumulate a future amount For the following.pdf
Number of years needed to accumulate a future amount For the following.pdfNumber of years needed to accumulate a future amount For the following.pdf
Number of years needed to accumulate a future amount For the following.pdfactexerode
 
Nowadays- we concern about health and nutrition as well as well-balanc.pdf
Nowadays- we concern about health and nutrition as well as well-balanc.pdfNowadays- we concern about health and nutrition as well as well-balanc.pdf
Nowadays- we concern about health and nutrition as well as well-balanc.pdfactexerode
 
Now your job is to write a Kotlin program to maintain the team roster-.pdf
Now your job is to write a Kotlin program to maintain the team roster-.pdfNow your job is to write a Kotlin program to maintain the team roster-.pdf
Now your job is to write a Kotlin program to maintain the team roster-.pdfactexerode
 
Now that the DFD has been created- it is time to build an object model.pdf
Now that the DFD has been created- it is time to build an object model.pdfNow that the DFD has been created- it is time to build an object model.pdf
Now that the DFD has been created- it is time to build an object model.pdfactexerode
 
Note- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdf
Note- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdfNote- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdf
Note- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdfactexerode
 
Now add to your GUI to allow the user to select a CUBES project to cla (1).pdf
Now add to your GUI to allow the user to select a CUBES project to cla (1).pdfNow add to your GUI to allow the user to select a CUBES project to cla (1).pdf
Now add to your GUI to allow the user to select a CUBES project to cla (1).pdfactexerode
 
Note on vegetarians and type of vegetarians-Must be well explained.pdf
Note on vegetarians and type  of vegetarians-Must be well explained.pdfNote on vegetarians and type  of vegetarians-Must be well explained.pdf
Note on vegetarians and type of vegetarians-Must be well explained.pdfactexerode
 
Not yet answered Points out of 1-00 Flag question Marshall developed p.pdf
Not yet answered Points out of 1-00 Flag question Marshall developed p.pdfNot yet answered Points out of 1-00 Flag question Marshall developed p.pdf
Not yet answered Points out of 1-00 Flag question Marshall developed p.pdfactexerode
 
Normal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdf
Normal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdfNormal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdf
Normal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdfactexerode
 
Neman- a single parent- quit his job and started a small independent b.pdf
Neman- a single parent- quit his job and started a small independent b.pdfNeman- a single parent- quit his job and started a small independent b.pdf
Neman- a single parent- quit his job and started a small independent b.pdfactexerode
 
Night ventilation- or night flushing- works best in climates where day.pdf
Night ventilation- or night flushing- works best in climates where day.pdfNight ventilation- or night flushing- works best in climates where day.pdf
Night ventilation- or night flushing- works best in climates where day.pdfactexerode
 
Newton Industries has a relevant range exlending to 31-800 unts each m.pdf
Newton Industries has a relevant range exlending to 31-800 unts each m.pdfNewton Industries has a relevant range exlending to 31-800 unts each m.pdf
Newton Industries has a relevant range exlending to 31-800 unts each m.pdfactexerode
 
New DNA is formed- by copying off RNA molecule templates- when nucleot.pdf
New DNA is formed- by copying off RNA molecule templates- when nucleot.pdfNew DNA is formed- by copying off RNA molecule templates- when nucleot.pdf
New DNA is formed- by copying off RNA molecule templates- when nucleot.pdfactexerode
 
New devices and device platforms are continually being released as the.pdf
New devices and device platforms are continually being released as the.pdfNew devices and device platforms are continually being released as the.pdf
New devices and device platforms are continually being released as the.pdfactexerode
 
Networking- What are the unix commands - steps to do the following- -.pdf
Networking- What are the unix commands - steps to do the following- -.pdfNetworking- What are the unix commands - steps to do the following- -.pdf
Networking- What are the unix commands - steps to do the following- -.pdfactexerode
 
Network standard and technologies use TCP-IP model such as- Network Ac.pdf
Network standard and technologies use TCP-IP model such as- Network Ac.pdfNetwork standard and technologies use TCP-IP model such as- Network Ac.pdf
Network standard and technologies use TCP-IP model such as- Network Ac.pdfactexerode
 
netflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdf
netflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdfnetflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdf
netflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdfactexerode
 
Netflix offers not only streaming entertainment but also a system of a.pdf
Netflix offers not only streaming entertainment but also a system of a.pdfNetflix offers not only streaming entertainment but also a system of a.pdf
Netflix offers not only streaming entertainment but also a system of a.pdfactexerode
 
Negative control means a regulator molecule is A)bound- and transcript.pdf
Negative control means a regulator molecule is A)bound- and transcript.pdfNegative control means a regulator molecule is A)bound- and transcript.pdf
Negative control means a regulator molecule is A)bound- and transcript.pdfactexerode
 

More from actexerode (20)

Number of years to provide a given return In the information given in.pdf
Number of years to provide a given return In the information given in.pdfNumber of years to provide a given return In the information given in.pdf
Number of years to provide a given return In the information given in.pdf
 
Number of years needed to accumulate a future amount For the following.pdf
Number of years needed to accumulate a future amount For the following.pdfNumber of years needed to accumulate a future amount For the following.pdf
Number of years needed to accumulate a future amount For the following.pdf
 
Nowadays- we concern about health and nutrition as well as well-balanc.pdf
Nowadays- we concern about health and nutrition as well as well-balanc.pdfNowadays- we concern about health and nutrition as well as well-balanc.pdf
Nowadays- we concern about health and nutrition as well as well-balanc.pdf
 
Now your job is to write a Kotlin program to maintain the team roster-.pdf
Now your job is to write a Kotlin program to maintain the team roster-.pdfNow your job is to write a Kotlin program to maintain the team roster-.pdf
Now your job is to write a Kotlin program to maintain the team roster-.pdf
 
Now that the DFD has been created- it is time to build an object model.pdf
Now that the DFD has been created- it is time to build an object model.pdfNow that the DFD has been created- it is time to build an object model.pdf
Now that the DFD has been created- it is time to build an object model.pdf
 
Note- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdf
Note- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdfNote- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdf
Note- In C- integer division discards fractions- Ex- 6-4 is 1 (the 0-5.pdf
 
Now add to your GUI to allow the user to select a CUBES project to cla (1).pdf
Now add to your GUI to allow the user to select a CUBES project to cla (1).pdfNow add to your GUI to allow the user to select a CUBES project to cla (1).pdf
Now add to your GUI to allow the user to select a CUBES project to cla (1).pdf
 
Note on vegetarians and type of vegetarians-Must be well explained.pdf
Note on vegetarians and type  of vegetarians-Must be well explained.pdfNote on vegetarians and type  of vegetarians-Must be well explained.pdf
Note on vegetarians and type of vegetarians-Must be well explained.pdf
 
Not yet answered Points out of 1-00 Flag question Marshall developed p.pdf
Not yet answered Points out of 1-00 Flag question Marshall developed p.pdfNot yet answered Points out of 1-00 Flag question Marshall developed p.pdf
Not yet answered Points out of 1-00 Flag question Marshall developed p.pdf
 
Normal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdf
Normal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdfNormal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdf
Normal red blood cell shapes is a dominant trait- Sicklocell anemia is.pdf
 
Neman- a single parent- quit his job and started a small independent b.pdf
Neman- a single parent- quit his job and started a small independent b.pdfNeman- a single parent- quit his job and started a small independent b.pdf
Neman- a single parent- quit his job and started a small independent b.pdf
 
Night ventilation- or night flushing- works best in climates where day.pdf
Night ventilation- or night flushing- works best in climates where day.pdfNight ventilation- or night flushing- works best in climates where day.pdf
Night ventilation- or night flushing- works best in climates where day.pdf
 
Newton Industries has a relevant range exlending to 31-800 unts each m.pdf
Newton Industries has a relevant range exlending to 31-800 unts each m.pdfNewton Industries has a relevant range exlending to 31-800 unts each m.pdf
Newton Industries has a relevant range exlending to 31-800 unts each m.pdf
 
New DNA is formed- by copying off RNA molecule templates- when nucleot.pdf
New DNA is formed- by copying off RNA molecule templates- when nucleot.pdfNew DNA is formed- by copying off RNA molecule templates- when nucleot.pdf
New DNA is formed- by copying off RNA molecule templates- when nucleot.pdf
 
New devices and device platforms are continually being released as the.pdf
New devices and device platforms are continually being released as the.pdfNew devices and device platforms are continually being released as the.pdf
New devices and device platforms are continually being released as the.pdf
 
Networking- What are the unix commands - steps to do the following- -.pdf
Networking- What are the unix commands - steps to do the following- -.pdfNetworking- What are the unix commands - steps to do the following- -.pdf
Networking- What are the unix commands - steps to do the following- -.pdf
 
Network standard and technologies use TCP-IP model such as- Network Ac.pdf
Network standard and technologies use TCP-IP model such as- Network Ac.pdfNetwork standard and technologies use TCP-IP model such as- Network Ac.pdf
Network standard and technologies use TCP-IP model such as- Network Ac.pdf
 
netflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdf
netflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdfnetflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdf
netflix uses DIGITAL MEDIA STRATEGIES such as rmail marketing- connect (1).pdf
 
Netflix offers not only streaming entertainment but also a system of a.pdf
Netflix offers not only streaming entertainment but also a system of a.pdfNetflix offers not only streaming entertainment but also a system of a.pdf
Netflix offers not only streaming entertainment but also a system of a.pdf
 
Negative control means a regulator molecule is A)bound- and transcript.pdf
Negative control means a regulator molecule is A)bound- and transcript.pdfNegative control means a regulator molecule is A)bound- and transcript.pdf
Negative control means a regulator molecule is A)bound- and transcript.pdf
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 

Need help with the TODO's (DONE IN C++) #pragma once #include -funct.pdf

  • 1. 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;
  • 2. 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() {
  • 3. // 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 }
  • 4. 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 }
  • 5. 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
  • 6. } 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); template <typename KK, typename VV, typename CC> friend void printTree( const BinarySearchTree<KK, VV, CC>& bst, std::ostream & out ); template <typename KK, typename VV, typename CC> friend void printTree(typename BinarySearchTree<KK, VV, CC>::const_node_ptr t, std::ostream & out, unsigned depth );
  • 7. template <typename KK, typename VV, typename CC> friend void vizTree( typename BinarySearchTree<KK, VV, CC>::const_node_ptr node, std::ostream & out, typename BinarySearchTree<KK, VV, CC>::const_node_ptr prev ); template <typename KK, typename VV, typename CC> friend void vizTree( const BinarySearchTree<KK, VV, CC> & bst, std::ostream & out ); }; template <typename KK, typename VV, typename CC> std::ostream& printNode(std::ostream & o, const typename BinarySearchTree<KK, VV, CC>::node & bn) { return o << '(' << bn.element.first << ", " << bn.element.second << ')'; } template <typename KK, typename VV, typename CC> void printLevelByLevel( const BinarySearchTree<KK, VV, CC>& bst, std::ostream & out = std::cout ) { using node = typename BinarySearchTree<KK, VV, CC>::node;
  • 8. using node_ptr = typename BinarySearchTree<KK, VV, CC>::node_ptr; using const_node_ptr = typename BinarySearchTree<KK, VV, CC>::const_node_ptr; // TODO -- Guide in Instructions } template <typename KK, typename VV, typename CC> void printTree( const BinarySearchTree<KK, VV, CC> & bst, std::ostream & out = std::cout ) { printTree<KK, VV, CC>(bst._root, out ); } template <typename KK, typename VV, typename CC> void printTree(typename BinarySearchTree<KK, VV, CC>::const_node_ptr t, std::ostream & out, unsigned depth = 0 ) { if (t != nullptr) { printTree<KK, VV, CC>(t->right, out, depth + 1); for (unsigned i = 0; i < depth; ++i) out << 't'; printNode<KK, VV, CC>(out, *t) << 'n'; printTree<KK, VV, CC>(t->left, out, depth + 1); } } template <typename KK, typename VV, typename CC> void vizTree( typename BinarySearchTree<KK, VV, CC>::const_node_ptr node,
  • 9. std::ostream & out, typename BinarySearchTree<KK, VV, CC>::const_node_ptr prev = nullptr ) { if(node) { std::hash<KK> khash{}; out << "t" "node_" << (uint32_t) khash(node->element.first) << "[label="" << node->element.first << " [" << node->element.second << "]"];" << std::endl; if(prev) out << "tnode_" << (uint32_t) khash(prev->element.first) << " -> "; else out << "t"; out << "node_" << (uint32_t) khash(node->element.first) << ";" << std::endl; vizTree<KK, VV, CC>(node->left, out, node); vizTree<KK, VV, CC>(node->right, out, node); } } template <typename KK, typename VV, typename CC> void vizTree( const BinarySearchTree<KK, VV, CC> & bst, std::ostream & out = std::cout
  • 10. ) { out << "digraph Tree {" << std::endl; vizTree<KK, VV, CC>(bst._root, out); out << "}" << std::endl; }