//============================================================================// Name: BinarySearchTree.cpp// Author: JYour name// Version: 1.0// Copyright: Copyright © 2017 SNHU COCE// Description : Hello World in C++, Ansi-style//============================================================================#include <iostream>#include <time.h>#include <Windows.h>#include "CSVparser.hpp"using namespace std;//============================================================================// Global definitions visible to all methods and classes//============================================================================// forward declarationsdouble strToDouble(string str, char ch);// define a structure to hold bid informationstruct Bid {string bidId; // unique identifierstring title;string fund;double amount;Bid() {amount = 0.0;}};// Internal structure for tree nodestruct Node {Bid bid;Node* left;Node* right;// default constructorNode() {left = nullptr;right = nullptr;}// initialize with a bidNode(Bid aBid) {bid = aBid;left = nullptr;right = nullptr;}//// create the key for the given bid//unsigned int key = hash(atoi(bidId.c_str()));//Node* node = &(nodes.at(key));//// if entry found for the key//if (node != nullptr && node->key != UINT_MAX
//&& node->bid.bidId.compare(bidId) == 0) {//return node->bid;//}//// if no entry found for the key//if (node == nullptr || node->key == UINT_MAX) {//return bid;//}//while (node != nullptr) {//// if the current node matches, return it//if (node->key != UINT_MAX && node->bid.bidId.compare(bidId) == 0) {//return node->bid;//}//node = node->next;//}//return bid;};//============================================================================// Binary Search Tree class definition//============================================================================/*** Define a class containing data members and methods to* implement a binary search tree*/class BinarySearchTree {private:Node* root;//void addNode(Node* node, Bid bid);void inOrder(Node* node);//Node* removeNode(Node* node, string bidId);int size = 0;public:BinarySearchTree();virtual ~BinarySearchTree();void InOrder();void Insert(Bid bid);void Remove(string bidId);Bid Search(string bidId);int Size();};/*** Default constructor*/BinarySearchTree::BinarySearchTree() {// FixMe (1): initialize housekeeping variables//root is equal to nullptrthis->root = nullptr;}
/*** Destructor*/BinarySearchTree::~BinarySearchTree() {// recurse from root deleting every node}/*** Traverse the tree in order*/void BinarySearchTree::InOrder() {// FixMe (2): In order root// call inOrder fuction and pass rootinOrder(root);}/*** Traverse the tree in post-order*///void BinarySearchTree::PostOrder() {// FixMe (3): Post order root// postOrder root//}/*** Traverse the tree in pre-order*///void BinarySearchTree::PreOrder() {//// FixMe (4): Pre order root//// preOrder root//}/*** Insert a bid*/void BinarySearchTree::Insert(Bid bid) {// FIXME (5) Implement inserting a bid into the tree// if root equarl to null ptr// root is equal to new node bid// else// add Node root and bidNode* currentNode = root;
Upload your study docs or become a
Course Hero member to access this document
Upload your study docs or become a
Course Hero member to access this document
End of preview. Want to read all 11 pages?
Upload your study docs or become a
Course Hero member to access this document
Term
Winter
Professor
NoProfessor
Tags
ASCII, bidID