C++ Programming!! Someone please help me with this program using trees!! Read Be
ID: 3824634 • Letter: C
Question
C++ Programming!! Someone please help me with this program using trees!! Read Below for details! Will rate!!
Use an ADT called BinTree to hold the binary tree and an ADT name BTNode to hold the binary tree nodes, you can make use of the code example “binary_tree_node”.
Each node in the binary tree must contain ONLY 3 data items.
a char variable to contain a single letter from the English alphabet
a pointer variable to point to a left child node
a pointer variable to point to a right child node
All valid input will be single characters, separated by one or more blanks. More than one input value may appear on a single line. Multiple lines of input may be present. Blank lines may appear in the input file. The file will not be entirely empty (i.e. there will be at least a single valid character). Also we assume that each character will appear at most once in the input file.
(4)For each input character, you are to place it into the binary tree. When properly placed, an in-order traversal of the binary tree will allow the data to be printed in non-decreasing order.
Implement the BinTree and BTNode ADTs and their methods to do the following traversals on your binary tree. During any traversal, your algorithm must print the character content out to the screen and to an output file named "outfile.txt". You should always display a copy of the input along with the resultant output. Below are the traversals to implement.
Post-Order Traversal
Pre-Order Traversal
In-Order Traversal
Below is a suggestion of what would be an acceptable format of output file. Make sure it is well labeled and very easy to understand without having to look at ANYTHING else.
Tree Traversal Report
Input Data: m f s d h o u a e g i n q t x
Post-Order: a e d g i h f n q o t x u s m
Pre-Order : m f d a e h g i s o n q u t x
In-Order : a d e f g h i m n o q s t u x
Explanation / Answer
//Example program for Binary search
# include <stdio.h>
# include <conio.h>
# include <stdlib.h>
void main()
{
int n,a[100],i,j,temp,num,low,high,mid,limit;
clrscr();
printf(" Enter how many numbers ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf(" Enter %d number ",i);
scanf("%d",&a[i]);
}
limit=n-1;
for(i=0;i<n-1;i++)
for(j=0;j<limit-i;j++)
if(a[j+1]<a[j])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
printf(" Enter the number to search ");
scanf("%d",&num);
low=0;
high=n-1;
while(low<=high)
{
mid=(low+high)/2;
if(num==a[mid])
{
printf(" Element is at %d location ",mid);
getch();
exit(0);
}
else if(num<a[mid]) high=mid-1;
else if(num>a[mid]) low=mid+1;
}
printf(" Given element is not found ");
getch();
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.