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
PLEASE HELP QUICK ASAP NO LINKS PYTHON CODING
Mademuasel [1]

Answer:

its for the movement

Explanation:

6 0
3 years ago
Read 2 more answers
In popular usage and in the media, the term ________ often describes someone who breaks into a computer system without authoriza
ch4aika [34]
The answer here is hacker
6 0
3 years ago
A _____ is the useful part of a transmission through a network.
Crazy boy [7]

Answer: LAN

Explanation:

3 0
3 years ago
When doing a complex presentation, which of the following would be the best tool to begin designing your presentation?
Dafna1 [17]
An outline can be a best tool to begin describes a presentation....
4 0
4 years ago
Read 2 more answers
What are the information ethics associated with IP
Naily [24]

Answer:

The IP stands for intellectual property. And the information ethics related to the IP are the transaction privacy, piracy and the privacy for the ease and giveaways, investigation, namelessness. The trade details must be kept private, and not disclosed to anybody, and the piracy is never allowed. Also, the privacy of all sorts must be ensured for ease and giveaways, surveillance, and confidentiality.

Explanation:

Please check the answer section.

3 0
4 years ago
Other questions:
  • When you compile your program, the compiler identifies the logic errors and suggests how to correct them?
    14·1 answer
  • What has the dogo argentino been bred to do?​
    12·1 answer
  • Deon is required to provide the citation information for his sources. What type of information should he collect from his source
    10·2 answers
  • Write a method named circleArea that accepts the radius of a circle as a parameter (as a real number) and returns the area of a
    12·1 answer
  • python Write a program that will take a file named Celsius.dat that contains a list of temperatures in Celsius (one per line), a
    9·1 answer
  • I need it ASAP, brainliest to whoever answers correctly!
    10·1 answer
  • Welcome back to school people!
    15·2 answers
  • Which of the following should be performed to prove the value of a security awareness training program?
    8·1 answer
  • Indicate if the statement is true or false False 1. A spreadsheet cannot recalculate after you have changed data in your workshe
    15·1 answer
  • a) In an office, it is required to take hundreds of copies of the same type written document. Which traditional method of docume
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!