Program for COSC 504 Summer 2018 Fill a tree called Pine with 25 elements from a
ID: 3910764 • Letter: P
Question
Program for COSC 504 Summer 2018
Fill a tree called Pine with 25 elements from an input file.
Traverse the tree using each of the following methods.
Print the smallest element in the binary search tree, Pine.
Find the number of edges between the root of the tree and the node that contains the smallest value in the tree. Return the count to the calling unit.
Count the number of internal nodes in the original tree, Pine. Print the count and return it to the calling program.
Write a function that will create a new tree, composed of the values in the original tree in reverse order. For example: if the string value in the node is “house” then the new value in the node will be “esuoh.” The structure of the original tree remains unchaged.
Write a function that will replace an indicated value, oldval, with a new value, keeping the tree as a binary search tree. The tree remains otherwise unchanged.
- Implement a function that will make a copy of the original tree, Pine. Call the keeping the tree as a binary search tree. The tree remains otherwise unchanged. new tree CopyPine.
Implement a function that will determine whether two trees are equal. Use the first twelve entries to create Mtree. Use the next twelve entries to make Ntree. Make a copy of Ntree called CopyNtree. Compare Mtree and Ntree and get the results. Compare Ntree and CopyNtree and get the results.
Implement a function that will determine whether the tree is a 0-2 tree.
Implement a function that will find the maximum value in the tree.
Create a list of 11 words that form a 0-2 binary search tree called ZTTree. Place the words in the comment section of the subprogram. Perform a preorder, an inorder, and a postorder traversal of the 0-2 tree.
. Write a function that will determine whether the 0-2 tree, ZTTree, is a symmetric tree.
Write a function that will print the binary search tree Pine, from the maximum element to the minimum element.
Write a function to determine whether a binary tree is a full binary tree.
Count the leaf nodes in the original tree, Pine.
Write a function that will create a new tree, Oak, composed of the in reverse order. The original tree remains unchanged.
Write function that will replace a given value in the tree, Pine, with a new value keeping the tree as a binary search tree. The tree remains otherwise unchanged.
Implement a function that will determine whether two trees, Mtrees and Ntree are equal.
Implement a function that will find the minimum value in the tree, Pine.
Implement a function that will combine two binary search trees Atree and Btree, into a single binary search tree.
Write a function to find the height of a binary search tree.
Write a function that will swap the contents of each pair of sibling nodes in a binary search tree.
Write a function that will determine whether one tree is the mirror image of another tree. Create two such trees.
-
using c++ language
Program for COSC 504 Summer 2018 Write a program that will operations. The elements in the tree lengths. appropriately l create a binary search tree and carry out the following Inptdn in the tree are strings of printable characters of variable nput and prothe ginal tree, all new.br that you must demonstrate each action taken by printing program. Theed trees, and any quantities that may be generated by the output file usage is required. You must comment your each action be generat newly will be discussed in class. averse thaled Pine with 25 elements from an input file. Traverse the tree using each of the Pint the smallest element in the binary search tree, Pine. the smallest value in the tree. Return the count to the calling unit. return it to the calling program - traversal methods. e number of edges between the root of the tree and the node that contains of internal nodes in the original tree, Pine. Print the count and ion that will create a new tree, composed of the values in the original - Find th Write a funct - in reverse order. For example: if the string value in the node is "house" then the new value in the node will be "esuoh." The structure of the original tree remains unchanged. - Write a function that will replace an indicated value, oldval, with a new value, - Implement a function that will make a copy of the original tree, Pine. Call the keeping the tree as a binary search tree. The tree remains otherwise unchanged. new tree CopyPine. Implement a function that will determine whether two trees are equal. Use the first twelve entries to create Mtree. Use the next twelve entries to make Ntree. Make a copy of Ntree called CopyNtree. Compare Mtree and Ntree and get the results. Compare Ntree and CopyNtree and get the results. Implement a function that will determine whether the tree is a 0-2 tree. Implement a function that will find the maximum value in the tree. Create a list of 11 words that form a 0-2 binary search tree called ZTTree. Place the words in the comment section of the subprogram. Perform a preorder, an inorder, and a postorder traversal of the 0-2 tree. - - . Write a function that will determine whether the 0-2 tree, ZTTree, is a symmetric tree. Write a function that will print the binary search tree Pine, from the maximum element to the minimum element Write a function to determine whether a binary tree is a full binary tree. - Count the leaf nodes in the original -Write a function that will create a new tree, Oak, composed of the in reverse order. The original tree remains unchanged. on that will replace a given value in the tree, Pine, with a new Write a functias a binary search tree. The tree remains otherwise uncha ValExplanation / Answer
//taking question from picture//
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<fstream>
using namespace std;
struct node
{
string data;
struct node *left, *right;
};
struct node *newNode(string item)
{
struct node *temp = (struct node *)malloc(sizeof(struct node));
temp->data = item;
temp->left = temp->right = NULL;
return temp;
}
//traversal in all forms//
void inorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
cout<< root->data;
inorder(root->right);
}
}
void postorder(struct node *root)
{
if (root != NULL)
{
inorder(root->left);
inorder(root->right);
cout<< root->data;
}
}
void preorder(struct node *root)
{
if (root != NULL)
{
cout<< root->data;
inorder(root->left);
inorder(root->right);
}
}
struct node* insert(struct node* node, string data)
{
if (node == NULL) return newNode(data);
if ((data.compare(node->data))<0)
node->left = insert(node->left, data);
else if ((data.compare(node->data))>0)
node->right = insert(node->right, data);
return node;
}
int smallest_no(struct node*n){
int min=-999;
int edge=0;
while(n->left!=NULL){
edge++;
n=n->left;
}
cout<<"smallest no is "<<n->data<<endl;
return edge; //no of edges between root and smallest no//
}
int main(){
struct node *n;
ifstream f;
f.open("abc.txt");
int count=25;
string str;
while((count>0)&&(getline(f,str))){ //storing 25 elementd from inputfile//
insert(n,str);
count--;
}
int e=smallest_no(n);
cout<<"no of edge between root and smallest no is "<<e<<endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.