1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
dangina [55]
4 years ago
12

Write a BCPL program that accepts strings from the user and builds them into a binary tree. Whenever the user types * as the inp

ut string, your program should print out the entire contents of the tree in alphabetical order, then delete the entire tree, starting again with an empty one.
Computers and Technology
1 answer:
ANEK [815]4 years ago
4 0

The program is:

#include<stdio.h>

#include<stdlib.h>

#include<string.h>

typedef struct def_nodo

{char num[500];

 struct def_nodo *izq, *der;

}Tiponodo;

void inserta(Tiponodo **insert, char i[]);

void borra(Tiponodo *p);

void imprime_orden(Tiponodo *p);

int main(void)

{

 char nombre[500];

 Tiponodo *raiz;

 raiz=NULL;

   do{printf("Give me the string you want: ");    

   __fpurge(stdin);

   gets(nombre);

inserta(&raiz,nombre);  

}while(strcmp(nombre,"*")!=0);

 imprime_orden(raiz);

   borra(raiz);

}

void inserta(Tiponodo **insert, char i[])//In this function we insert the new string in our tree

{Tiponodo *avanza, *nuevo;

 

 avanza=*insert;

 

     if((nuevo=(Tiponodo *)malloc(sizeof(Tiponodo)))==NULL)

{printf("no hay espacio libre");

  exit(1);

}

     strcpy(nuevo->num,i);

     

     nuevo->izq=NULL;

     nuevo->der=NULL;

     

     while(avanza!=NULL)

{

      if(strcmp(avanza->num,i)<0)

 {if(avanza->der!=NULL)

     avanza=avanza->der;

   else

     {avanza->der=nuevo;

       return;

     }

 }

      if(strcmp(avanza->num, i)>=0)

 {if(avanza->izq!=NULL)

     avanza=avanza->izq;

   else

     {avanza->izq=nuevo;

       return;

     }

 }  

 

}

     avanza=nuevo;

     *insert=avanza;

}

void imprime_orden(Tiponodo *p)//we use this function to print the tree

{if(p!=NULL)

   {imprime_orden(p->izq);

     printf("%s \n", p->num);

     imprime_orden(p->der);

   }

}

void borra(Tiponodo *p)//we use this function to delete the binary tree

{if(p!=NULL)

   {borra(p->izq);

     borra(p->der);

     free(p);

   }

}

You might be interested in
Select the best answer from the drop-down menu.
Orlov [11]

Answer:

1) R<u>easoning</u>

<u>2)Nonverbal</u>

<u>3)Generating solutions.</u>

<u>4)Decision making</u>.

<u>--------------------------------------</u>

Robert is reviewing complex information and data concerning a new product launch to determine the cause of some product failures. He is primarily using <u>reasoning</u> skills.

Reasoning through a problem requires an understanding between verbal and <u>nonverbal</u> ideas.

When you use reasoning skills and past experience to brainstorm ideas you are <u>generating solutions.</u>

When you narrow down solution ideas, then select the best one, you are engaging in <u>decision making</u>.

<u>OAmalOHopeO</u>

8 0
3 years ago
Read 2 more answers
2. Write these functions definitions:
GREYUIT [131]

Answer:

Complete the code with the following code segment:

void add2Numbers(){

   int num1, num2;

   cout<<"Enter any two numbers: ";

   cin>>num1>>num2;

   cout<<num1+num2;

}

void sub2Numbers(){

   int num1, num2;

   cout<<"Enter any two numbers: ";

   cin>>num1>>num2;

   cout<<num1-num2;

}

void mul2Numbers(){

   int num1, num2;

   cout<<"Enter any two numbers: ";

   cin>>num1>>num2;

   cout<<num1*num2;

}

void div2Numbers(){

   int num1, num2;

   cout<<"Enter any two numbers: ";

   cin>>num1>>num2;

if(num2==0){

cout<<"Division by 0 is invalid";

}else{

   cout<<(float)num1/num2;}

}

Explanation:

The function added to this solution are:

  • add2Numbers
  • sub2Numbers
  • mul2Numbers
  • div2Numbers

Each of the functions

  • declares two integers num1 and num2
  • prompt user for inputs
  • gets user inputs from the user

For add2Numbers() function:

This line adds the two integer numbers and prints the result

   cout<<num1+num2;

For sub2Numbers() function:

This line subtracts the two integer numbers and prints the result

   cout<<num1-num2;

For mul2Numbers() function:

This line multiplies the two integer numbers and prints the result

   cout<<num1*num2;

For div2Numbers() function:

This if condtion checks if the denominator is 0

if(num2==0){

If yes, the following is printed

cout<<"Division by 0 is invalid";

If otherwise, the division is calculated and the result is printed

   cout<<(float)num1/num2;

<em>See attachment for complete program</em>

Download cpp
7 0
3 years ago
____ are programs that enable the browser to work with an embedded object.
DerKrebs [107]
HTML's to learn more go to https://developer.mozilla.org/en-US/docs/Web/HTML/Element/embed
5 0
4 years ago
MaKe TeA In ThE AnSwErs
AfilCa [17]
Pineapples don’t taste good.
4 0
3 years ago
Once an alert is created you can no loner edit it's defining search true or false?
Darya [45]

Answer:

True...

Explanation:

Once an alert is created, you can no longer edit its defining search. Alerts can be shared to all apps. Alerts can send an email. Real-time alerts will run the search continuously in the background.

Hope this helps u

Brainliest please

3 0
3 years ago
Other questions:
  • How do media and networks interact
    11·1 answer
  • How do I turn of the noise canceling feature on my beats studio wireless?
    13·1 answer
  • Is a set of standards that define how email is to be processed between mail servers is exactly the same as smtp copies an e-mail
    10·1 answer
  • An argument is different from a parameter in that an argument
    11·2 answers
  • Should a social network own our social data? Is it an invasion of privacy for social networks to collect and use the information
    6·1 answer
  • When you first launch presentation software, how many blank slides will appear on your screen?
    5·2 answers
  • Assume that the int variables i, j and n have been declared, and n has been initialized. Write code that causes a "triangle" of
    11·1 answer
  • Need answer ASAP!!!!
    14·1 answer
  • What is wrong with line 3 ?
    11·1 answer
  • What is the difference between software hardware ???
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!