Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct tree{
- int n;
- struct tree *dir, *esq;
- }Ttree;
- void inserirOrdenado (Ttree **raiz, int n){//ordenado com repetição n recursivo
- Ttree *novo, *aux;
- if(*raiz == NULL){
- novo = (Ttree*)malloc(sizeof(Ttree));
- novo->n = n;
- novo->dir = NULL;
- novo->esq = NULL;
- *raiz = novo;
- }
- else{
- aux = *raiz;
- while(1){
- if(aux->n <= n){
- if(aux->dir == NULL){
- novo = (Ttree*)malloc(sizeof(Ttree));
- novo->n = n;
- novo->dir = NULL;
- novo->esq = NULL;
- aux->dir = novo;
- return;
- }
- aux = aux->dir;
- }
- else if(aux->n > n){
- if(aux->esq == NULL){
- novo = (Ttree*)malloc(sizeof(Ttree));
- novo->n = n;
- novo->dir = NULL;
- novo->esq = NULL;
- aux->esq = novo;
- return;
- }
- aux = aux->esq;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement