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

Please use C++ language and also, please provide codes and output. and please do

ID: 3836868 • Letter: P

Question

Please use C++ language and also, please provide codes and output. and please do it from scratch and there is 3 task to do so please complete those.

Please use C++ language ,, and do it from scratch.

Task 1:

Please create Lookup() and Insert() functions for Binary Search Tree examples in attached supplement.

(Attach Snipping Photos of Source Code Below)

Optional Implement example

1. Build 123() from attached supplement.

Task 2:

Please Implement

2. size() Problem demonstrates simple binary tree traversal

(Attach Snipping Photos of Source Code Below)








Task 3:

Please Implement

5. print Tree() Problem demonstrates simply binary tree traversal

Given a binary search tree (aka an "ordered binary tree"), iterate over the nodes to print them out in increasing order. So the tree...

  

Produces the output "1 2 3 4 5". This is known as an "inorder" traversal of the tree.

Hint: For each node, the strategy is: recur left, print the node data, recur right.

void print Tree(struct node* node) {

I 5 4 2

Explanation / Answer

#include <iostream>
#include<stdio.h>
#include<stdlib.h>

using namespace std;

struct node
{
int data;
struct node *left;
struct node *right;
};
  
void printTree(struct node* node)
{
if (node != NULL)
{
printTree(node->left);
cout <<node->data << " ";
printTree(node->right);
}
}

struct node *newNode(int item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->data = item;
temp->left = temp->right = NULL;
return temp;
}

struct node* insert(struct node* node, int data)
{
if (node == NULL)
return newNode(data);

if (data < node->data)
node->left = insert(node->left, data);
else if (data > node->data)
node->right = insert(node->right, data);   

return node;
}

struct node* lookup(struct node* root, int data)
{
if (root == NULL || root->data == data)
return root;
  
if (root->data < data)
return lookup(root->right, data);
return lookup(root->left, data);
}

int size(struct node* node)
{
if (node==NULL)
return 0;
else
return(size(node->left) + 1 + size(node->right));
}

int main()
{
struct node *root = NULL;
root = insert(root, 4);
insert(root, 2);
insert(root, 5);
insert(root, 1);
insert(root, 3);
  
cout << "Size of tree is: " << size(root) << endl;
  
cout << "Element of tree are: ";
printTree(root);
cout << endl;
  
  
  
return 0;
}