Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Compute this in C++ while using Queues and Nodes to link them to the Bina

ID: 3780237 • Letter: P

Question


Please Compute this in C++ while using Queues and Nodes to link them to the Binary Search Tree. 1. (Total 100 Points) Write a C++ program that implements a binary search tree (BST) to manage a number of integer items with different priorities. In order to do so, you will need to maintain a queue as an item in the tree. Each queue item is an integer. All items in a given queue will have the same priority. As a new item with a user-specified priority comes in, it should be enqueued in the queue with items of that priority. A new queue may need to created in case a queue with that priority does not exist. Use dynamic memory to manage nodes in the queue and BST. Absolutely no global variables anywhere in your code! Implement the following: (a) Constructor. (b) Destructor. (c) Overloaded copy constructor. (d) overloaded assignment operator. (e) overloaded operator to check if two trees are equal. A treetl is equal to t2 if for every queue in tl, a corresponding queue with the same priority exists in t2 with the same set of elements (the order of the elements in the queue does not matter Overloaded operator to show the contents of the tree. (g) Insert an item of specific priority. (h) heck for existence of an item of specific priority. i) Remove an item of specific priority. G) Clear all items of a specific priority. Use const keyword wherever appropriate. When referring to multiple trees, give a name to each tree as it is created by the user. Write a modular main program (that is with functions) to demonstrate all the features.

Explanation / Answer

#include<iostream>
#include<queue>
using namespace std;

class node {
public :
node *right;
node *left;
int info;
}*root;

queue<int> queueLinkedlist;

void BinarySearchTree(node *p)
{
   if(p!=NULL)
   {
       if(p->right!=NULL)
           queueLinkedlist.push(p->right->info);

       if(p->left!=NULL)
           queueLinkedlist.push(p->left->info);

       BinarySearchTree(p->right);
       BinarySearchTree(p->left);
   }
}

int main()
{
   node *tempNode = new node();
   tempNode->info = 1;

   root = tempNode;

   root->right = new node();
   root->right->info = 2;
   root->right->right = root->right->left = NULL;

   root->left = new node();
   root->left->info = 3;
   root->left->right = root->left->left = NULL;

   node *tmp = root;
   root=root->right;

   root->right = new node();
   root->right->info = 4;
   root->right->right = root->right->left = NULL;

   root->left = new node();
   root->left->info = 5;
   root->left->right = root->left->left = NULL;

   root = tmp;
   root = root->left;

   root->right = new node();
   root->right->info = 6;
   root->right->right = root->right->left = NULL;

   root->left = new node();
   root->left->info = 7;
   root->left->right = root->left->left = NULL;

   root = tempNode;
   node *it;
   it = root;

   queueLinkedlist.push(root->info);

   BinarySearchTree(root);
   for (std::queue<node*> queueLinkedlist(1, root); !queueLinkedlist.empty(); queueLinkedlist.pop()) {
       n = queueLinkedlist.front();
       process(n->info);
       if (n->left) queueLinkedlist.push(n->left);
       if (n->right) queueLinkedlist.push(n->right);
   }
   return 0;
}