ordenar arbol en orden ascendente (INORDEN) en c
Publicado por sebas (1 intervención) el 31/05/2009 16:37:27
necesito ke los nodos ke ingresen se organizen en orden ascendente(inorden) e imprimirlos, me ayudan ,,gracias
#include <stdlib.h>
#include <stdio.h>
struct arbol
{
int id;
struct arbol*ptrizquierdo;
struct arbol*ptrderecho;
struct arbol*ptrpadre;
};
typedef struct arbol agenda;
typedef struct arbol *ptragenda;
int main() {
int op=0,i=0;
ptragenda padre;
ptragenda cabecera=NULL;
ptragenda recorrido=NULL;
ptragenda impri=NULL;
do {
printf(" MENU 1-INSERTAR UN NODO 2-IMPRIMIR LISTA DE NODOS 3-IMPRESION EN INORDEN 4-SALIR DIGITE LA OPCION QUE DESEA: ");
scanf( "%d",&op );
system("cls");
switch(op){
case 1:
padre=(agenda*)malloc(sizeof(agenda));
padre->id=0;
padre->ptrizquierdo=NULL;
padre->ptrderecho=NULL;
if(cabecera==NULL){
cabecera=padre;
recorrido=padre;
}
else {
recorrido->ptrizquierdo=padre;
recorrido=padre;
recorrido->ptrderecho=padre;
recorrido=padre;
}
printf(" INGRESE ID: ");
scanf( "%d",&padre->id);
break;
#include <stdlib.h>
#include <stdio.h>
struct arbol
{
int id;
struct arbol*ptrizquierdo;
struct arbol*ptrderecho;
struct arbol*ptrpadre;
};
typedef struct arbol agenda;
typedef struct arbol *ptragenda;
int main() {
int op=0,i=0;
ptragenda padre;
ptragenda cabecera=NULL;
ptragenda recorrido=NULL;
ptragenda impri=NULL;
do {
printf(" MENU 1-INSERTAR UN NODO 2-IMPRIMIR LISTA DE NODOS 3-IMPRESION EN INORDEN 4-SALIR DIGITE LA OPCION QUE DESEA: ");
scanf( "%d",&op );
system("cls");
switch(op){
case 1:
padre=(agenda*)malloc(sizeof(agenda));
padre->id=0;
padre->ptrizquierdo=NULL;
padre->ptrderecho=NULL;
if(cabecera==NULL){
cabecera=padre;
recorrido=padre;
}
else {
recorrido->ptrizquierdo=padre;
recorrido=padre;
recorrido->ptrderecho=padre;
recorrido=padre;
}
printf(" INGRESE ID: ");
scanf( "%d",&padre->id);
break;
Valora esta pregunta
0