Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can you please create pseudocode for the code below: #include #include #include CSVparser.hpp using namespace std; / / = = = = = =

Can you please create pseudocode for the code below:
#include
#include
#include "CSVparser.hpp"
using namespace std;
//============================================================================
// Global definitions visible to all methods and classes
//============================================================================
// forward declarations
double strToDouble(string str, char ch);
// define a structure to hold bid information
struct Bid {
string bidId; // unique identifier
string title;
string fund;
double amount;
Bid(){
amount =0.0;
}
};
// Internal structure for tree node
struct Node {
Bid bid;
Node* left;
Node* right;
// default constructor
Node(){
left = nullptr;
right = nullptr;
}
// initialize with a bid
Node(Bid aBid) : Node(){
bid = aBid;
}
};
//============================================================================
// 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);
public:
BinarySearchTree();
virtual ~BinarySearchTree();
void InOrder();
void Insert(Bid bid);
void Remove(string bidId);
Bid Search(string bidId);
};
/**
* Default constructor
*/
BinarySearchTree::BinarySearchTree(){
root = nullptr; // Initialize root to nullptr
}
/**
* Destructor
*/
BinarySearchTree::~BinarySearchTree(){
// Recursively delete nodes starting from the root
while (root != nullptr){
Remove(root->bid.bidId);
}
}
/**
* Traverse the tree in order (left, root, right)
*/
void BinarySearchTree::InOrder(){
inOrder(root);
}
/**
* Insert a bid into the tree
*/
void BinarySearchTree::Insert(Bid bid){
if (root == nullptr){
root = new Node(bid); // Create root node if the tree is empty
} else {
addNode(root, bid); // Call the recursive addNode method to insert the bid
}
}
/**
* Remove a bid from the tree
*/
void BinarySearchTree::Remove(string bidId){
root = removeNode(root, bidId);
}
/**
* Search for a bid in the tree
*/
Bid BinarySearchTree::Search(string bidId){
Node* current = root;
while (current != nullptr){
if (current->bid.bidId == bidId){
return current->bid; // Found the bid, return it
} else if (bidId < current->bid.bidId){
current = current->left; // Traverse left if bidId is smaller
} else {
current = current->right; // Traverse right if bidId is larger
}
}
Bid emptyBid; // Return an empty bid if not found
return emptyBid;
}
/**
* Add a bid to a specific node (recursive)
*
* @param node Current node in tree
* @param bid Bid to be added
*/
void BinarySearchTree::addNode(Node* node, Bid bid){
if (bid.bidId < node->bid.bidId){
if (node->left == nullptr){
node->left = new Node(bid); // Create a new node if left child is null
} else {
addNode(node->left, bid); // Recursive call to traverse left subtree
}
} else {
if (node->right == nullptr){
node->right = new Node(bid); // Create a new node if right child is null
} else {
addNode(node->right, bid); // Recursive call to traverse right subtree
}
}
}
/**
* Remove a bid from a node (recursive)
*
* @param node Current node in tree
* @param bidId Bid ID to be removed
* @return Updated node structure after removal
*/
Node* BinarySearchTree::removeNode(Node* node, string bidId){
if (node == nullptr){
return nullptr; // Return nullptr if the tree is empty
}
if (bidId < node->bid.bidId){
node->left = removeNode(node->left, bidId); // Recursively search in the left subtree
} else if (bidId > node->bid.bidId){
node->right = removeNode(node->right, bidId); // Recursively search in the right subtree
} else {
if (node->left == nullptr){
Node* tempNode = node->right;
delete node;
return tempNode; // Return the right child if left child is null
} else if (node->right == nullptr){
Node* tempNode = node->left;
delete node;
return tempNode; // Return the left child if right child is null
}
// If the node has two children, find the minimum value node in the right subtree (successor)
Node* tempNode = node->right;
while (tempNode->left != nullptr){

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Create a workflow analysis.

Answered: 1 week ago