Question

Fill a tree called Pine with 25 elements from an input file. Traverse the tree using...

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++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

` #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;

Add a comment
Know the answer?
Add Answer to:
Fill a tree called Pine with 25 elements from an input file. Traverse the tree using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • linux help Create a file called trees, containing the following individual lines: Oak tree Pine Tree...

    linux help Create a file called trees, containing the following individual lines: Oak tree Pine Tree Spruce tree Cottonwood Maple tree Pine Tree Copy in the contents of the trees to more_trees file. Next, add the following trees at the end of the list. Redwood Willow tree Use a command to compare the trees and more_trees files and show the differences in terms of individual lines that differ. Determine the number of bytes in both the trees and more trees...

  • using java to write,show me the output. please write some common. You CAN NOT use inbuild...

    using java to write,show me the output. please write some common. You CAN NOT use inbuild functions for Tree ADT operations. using code below to finsih public class Main {    public static void main(String[] args) {        BinaryTree tree = new BinaryTree(); tree.root = new Node(1); tree.root.left = new Node(2); tree.root.right = new Node(3); tree.root.left.left = new Node(4); tree.root.left.right = new Node(5); tree.root.right.left = new Node(6); tree.root.right.right = new Node(7); tree.root.left.left.left = new Node(8); tree.root.left.left .right= new Node(9);...

  • Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes...

    Answer the following question(s) concerning implementing recursive functions to perform operations on linked lists of nodes arranged as binary trees. For these questions, use the following struct definition for the nodes of the tree (we will not templatize the node here, so you do not have to write template functions for these questions, just assume trees of <int> values): struct BinaryTreeNode { int item; BinaryTreeNode* left; BinaryTreeNode* right; }; ---------------------------------------------- Given a node for a Binary Tree and an (integer)...

  • C++ Vectors and Binary Search Trees • Write a program that takes from the user n...

    C++ Vectors and Binary Search Trees • Write a program that takes from the user n integers and stores them a vector of int. Then, create a function insert After that takes first Value and second Value. This function searches for each occurrence of first Value in the vector and insert the second Value after it in the same vector. The first and second values are taken from the user. • Create another function that creates a Binary Search Tree...

  • Using C Please comment Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing...

    Using C Please comment Part 1: BST Create a link based Binary Search tree composed of a Node and a Tree struct. You should have a header file, BST.h, with the following: o Node struct containing left, right, and parent pointers, in addition to holding an Data struct value Tree struct containing a pointer to the root of the tree A function declaration for a function that allocates a tree, and initializes the root to NULL o o o A...

  • Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate ins...

    Binary Search Tree Part A: The code attached in this document is a sample code to demonstrate insert operation in binary search tree. Please fill in the missing part for the insert method to make the program work. The expected output should be as follows. 20 30 40 50 60 70 80 Part B: Find Lowest Common Ancestor (LCA) of a Binary Search Tree. According to WikiPedia definition , The lowest common ancestor is defined between two nodes v and...

  • (in C) Binry Srch tree problem: 1. Need to read words from a “in” text file...

    (in C) Binry Srch tree problem: 1. Need to read words from a “in” text file and build a binary search tree. (1st line will state number of elements) 2. strcmp() can be used to compare data and decide were to insert a new node. 3. The output should include: -print the tree as in-order traversal. -print the character count in the tree. -Ask user input for a word to search, print an output if either found or not. (typing...

  • Write a program, called wordcount.c, that reads one word at a time from the standard input....

    Write a program, called wordcount.c, that reads one word at a time from the standard input. It keeps track of the words read and the number of occurrences of each word. When it encounters the end of input, it prints the most frequently occurring word and its count. The following screenshot shows the program in action: adminuser@adminuser-VirtualBox~/Desktop/HW8 $ wordCount This is a sample. Is is most frequent, although punctuation and capitals are treated as part of the word. this is...

  • WİTH C LANGUAGE Write a program that counts the leaves of a given binary tree. Hint: You will make a small (and smar...

    WİTH C LANGUAGE Write a program that counts the leaves of a given binary tree. Hint: You will make a small (and smart) update to the add function we discussed in class. a) 125 pointsl Create the following binary trees by creating the nodes (malloc) and setting the related pointers (leftChild, rightChild). Make content random. 60 50 40 60 70 30 45 42 b) 125 points Display the trees on screen the way we did in slide 9 using listAll...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT