Dev - C++ - ARBOLES EN POSTORDEN

 
Vista:

ARBOLES EN POSTORDEN

Publicado por Nur la dueña de tu cora (2 intervenciones) el 09/02/2020 23:45:24
Hola¡ Necesito ayuda con este código si me pueden dar alguna recomendación de que podría hacer

//Este es el enunciado
Crear dos funciones; una que permita insertar h_izq y otra que permita insertar h_der

Si es NULL insertar el valor en el NULL
Si no es NULL enviar un mensaje que diga que el nodo esta ocupado//


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdlib.h>
#include <stdio.h>
#define nuevo (struct nodo *)malloc(sizeof(struct nodo))
struct nodo {
	int info; struct nodo *h_izq, *h_der;
} *C, *p, *q, *r;
int mostrar_nodo(struct nodo *s) {
	printf("%d", s->info); return 0;
}
 
int recorrer_en_postorden(struct nodo *s) {
	if (s!=NULL) {
		mostrar_nodo(s); printf ("  ");
		recorrer_en_postorden(s->h_izq);
		recorrer_en_postorden(s->h_der);
 
	}
	return 0;
}
 
int main() {	C=nuevo; C->info=36;
	C->h_izq=nuevo; C->h_der=nuevo;
	C->h_izq->info=18; C->h_der->info=45;
	p=nuevo; p->info=123; q=nuevo; q->info=9;
	C->h_izq->h_izq=p; C->h_izq->h_der=q;
	p->h_izq=NULL; p->h_der=NULL;
	q->h_izq=NULL; q->h_der=NULL;
	p=nuevo; p->info=54; q=nuevo; q->info=27;
	C->h_der->h_izq=p; C->h_der->h_der=q;
	p->h_izq=NULL; p->h_der=NULL;
	q->h_izq=NULL; q->h_der=NULL;
 
	printf("\n\n         "); recorrer_en_postorden(C);
	system ("pause");
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder