Question
c program that takes a seridalized text file of a tree of up to 32 nodes and builds its stick diagram as shown.
Example 1: Input text file: 10 6 1@5@@8@@ 12 @ 13 @ 20 19 16 @@@@ Output text file: 10 / 12 6 / 1 - 8 13 - - 5 20 19 - 16
Input text file: 10 8 1@7@@@@ 18 11 @ 16 13 @ 14 @@@23 21 @@@ Output text file: 10 8 18 / - - 1 9 11 1 - 23 / 21 7 16 7 13 -
0 0
Add a comment Improve this question Transcribed image text
Answer #1

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

#include<conio.h>



struct btnode
{
int value;
struct btnode *l;
struct btnode *r;
}*root = NULL, *temp = NULL, *t2, *t1;

void insert();
void create();
void display(struct btnode *t);
void search(struct btnode *t);

int flag = 1;

void main()
{
int ch;

printf("\nOPERATIONS ---");
printf("\n1 - Insert an element into tree\n");
printf("2 - display Traversal\n");
  printf("3 - Exit\n");
while(1)
{
printf("\nEnter your choice : ");
scanf("%d", &ch);
switch (ch)
{
case 1:
insert();
break;
case 2:
dislay(root);
break;
case 3:
exit(0);
default :   
printf("Wrong choice, Please enter correct choice ");
break;
}
}
}

/* This is to insert into node */
void insert()
{
create();
if (root == NULL)
root = temp;
else
search(root);
}

/* creation  of  node */
void create()
{
int data;

printf("Enter data of node to be inserted : ");
scanf("%d", &data);
temp = (struct btnode *)malloc(1*sizeof(struct btnode));
temp->value = data;
temp->l = temp->r = NULL;
  
}

void search(struct btnode *t)
{
if ((temp->value > t->value) && (t->r != NULL)) /* value more than root node value insert at right */
search(t->r);
else if ((temp->value > t->value) && (t->r == NULL))
t->r = temp;
else if ((temp->value < t->value) && (t->l != NULL)) /* value less than root node value insert at left */
search(t->l);
else if ((temp->value < t->value) && (t->l == NULL))
t->l = temp;
}

/* to display traversal */
void display(struct btnode *t)
{
if (root == NULL)
{
printf("No elements in a tree to display");
return;
}
if (t->l != NULL)
display(t->l);
printf("%d -> ", t->value);
if (t->r != NULL)
display(t->r);
}

Add a comment
Know the answer?
Add Answer to:
c program that takes a seridalized text file of a tree of up to 32 nodes...
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
  • Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays...

    Therefore, for this program you will read the data in the file named weatherdata_2.txt into arrays for the wind speed and for the temperature. You will then use the stored data to calculate and output the average wind speed and the average temperature. Create a constant with a value of 30 and use that to declare and loop through your arrays and as a divisor to produce your averages. Here is the data file (below). 1. 14 25 2. 12...

  • Write a program that will accept from the user a text file containing hurricane data along...

    Write a program that will accept from the user a text file containing hurricane data along with an output filename. The data consists of the year, the number of storms, the number of hurricanes, and the damage in millions of US Dollars. The first line contains the word “Years” followed by the first year listed and the last year listed separated by tabs. The following lines contain the data separated by tabs. A sample text file is available in this...

  • Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of...

    Trees and Heaps 1. Show that the maximum number of nodes in a binary tree of height h is 2h+1 − 1. 2. A full node is a node with two children. Prove that the number of full nodes plus one is equal to the number of leaves in a nonempty binary tree. 3. What is the minimum number of nodes in an AVL tree of height 15? 4. Show the result of inserting 14, 12, 18, 20, 27, 16,...

  • For C++ Write a program that randomly generates 100 integers and sorts them using radix sort....

    For C++ Write a program that randomly generates 100 integers and sorts them using radix sort. Note: Your output would not be the same as this sample output due to the randomness. Sample output: 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7...

  • Have to write the tree into a text file? JAVA CODE Binary search tree This is...

    Have to write the tree into a text file? JAVA CODE Binary search tree This is the tree public class Buildbst { private int data; private Buildbst left; private Buildbst right; //Set the binary search tree public Buildbst(int data) { this.data = data; this.left = null; this.right =null; } public int getData() { return data; } public void setData(int data) { this.data = data; } public Buildbst getLeft() { return left; } public void setLeft(Buildbst left) { this.left = left;...

  • The following python program totals up a bill based on how much was spent at each store.

    """ The following python program totals up a bill based on how much was spent at each store. """ INPUT_FILE = 'bill.txt' def main():     # TODO if __name__ == '__main__':     main()-------------------------------------------------------------------------------(This needs to be in a text file)9/2/19 [walMart] $12 9/21/19 [The Cheesecake Factory] $102 9/30/19 [Starbucks] $5 10/7/19 [WalMart] $17 10/22/19 [Starbucks] $8 10/28/19 [WalMart] $45--------------------------------------------------------------------------(This needs to be in a text file)4/1/20 [Burger King] $9 4/6/20 [Pizza Hut] $82 4/12/20 [Burger King] $117 4/17/20 [McDonald's] $14 4/19/20 [Burger King] $65 4/19/20 [Joan's Fabric] $18 4/23/20 [Apple bee's] $12 4/25/20 [Pizza Hut] $29 4/29/20 [Burger King] $7------------------------------------------------(Output sample for bill 1)  WalMart: $74   The Cheesecake Factory: $102   Starbucks: $13

  • In C++ Make a program that takes a positive integer 'n' and write an n x...

    In C++ Make a program that takes a positive integer 'n' and write an n x n matrix whose entries are listed as snail Example: (See picture) for n=6 Ej. Para n-6 2 2 2 20 21 22 23 24 7 19 32 33 34 258 18 31 36 35 26 9 17 30 29 28 27 10 16 15 14 13 12 11

  • Review the 6 karyotypes in Figure 10 and determine the chromosomal disorder. Record the chromosomal disorder...

    Review the 6 karyotypes in Figure 10 and determine the chromosomal disorder. Record the chromosomal disorder in Data Table 3. Describe the genotype of each chromosomal disorder and record in Data Table 3. Describe the phenotype of each chromosomal disorder and record in Data Table 3. Data Table 3: Karyotype to Genotype to Phenotype # Chromosomal Disorder Genotype Phenotype 1 2 3 4 5 6 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7...

  • Suppose there are 100 identical firms in the market and the luggage industry is perfectly competitive....

    Suppose there are 100 identical firms in the market and the luggage industry is perfectly competitive. What does the market supply curve look like? 20 19 18 17 16 15 14 13 12 11 A 10 9 8 7 6 5 4 20 19 18 17 16 15 14 13 12 11 A 10 8 7 6 2 1 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5...

  • Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16...

    Cork price: 16 10 15 10 17 11 14 13 11 14 11 16 18 16 10 17 14 14 16 7 10 12 19 15 16 14 9 12 21 13 10 16 12 16 13 17 17 13 14 18 11 12 15 16 13 18 16 17 12 12 14 9 11 14 19 13 11 17 11 13 15 14 18 18 18 12 10 11 13 14 11 14 18 13 13 19 17 14...

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