Red de conocimiento informático - Problemas con los teléfonos móviles - Problemas de programación de estructuras de datos

Problemas de programación de estructuras de datos

Al obtener un árbol binario completo, puede eliminar los que no desee.

#incluye & ltstdio.h & gt

#incluye & ltstdlib.h & gt

#incluye & ltconio.h & gt

#Definir NULL 0

#Definir caracteres de tipo de datos

typedef struct BinTreeNode * pbintrenode;

typedef PBinTreeNode * PBinTree

Estructura BinTreeNode

{Información del tipo de datos;

Enlace PBinTreeNode

Enlace PBinTreeNode

};

pbintrenode Crear _ BinTree(void);

árbol pbin Create _ bintree root(void)

{ PBinTree pbtree

Pb tree =(pbin tree)malloc(sizeof(struct BinTreeNode));

if(Pb tree = = NULL)Pb tree =(PBinTree)realloc(Pb tree, sizeof(struct BinTreeNode));

* Pb tree = Create _ BinTree();

return(Pb tree);

}

pbintrenode Create _ BinTreeNode(void)

{ PBinTreeNode pbnode

Nodo Pb =(PBinTreeNode)malloc(sizeof(struct BinTreeNode));

if(Nodo Pb == NULL)Nodo Pb =(PBinTreeNode)realloc(Nodo Pb, tamaño de(struct BinTreeNode));

else nodo Pb-& gt;llink = nodo Pb-& gt;rlink =(PBinTreeNode)NULL;

return(nodo Pb);

}

int isalphabet(char i)

{

if (i & gt= ' a ' & amp& ampi& lt= ' z ' | | i & gt= ' A ' & amp& ampi& lt='Z' || i=='@ ')

Devuelve 1;

En caso contrario, devuelve 0;

}

pbintrenode Create _ BinTree(void)

{ PBinTreeNode pbnode

Tipo de datos I

printf("Por favor; ingrese un carácter:\ t ");

fflush(stdin);

scanf("%c ", & ampI);

fflush(stdin) ;

Y (! isalphabet(i))

{

printf("Lo sentimos, los caracteres que ingresaste no están en el alfabeto, vuelve a ingresar:");

scanf(" %c ", & ampI);

fflush(stdin);

}

if(I = = ' @ ')Pb nodo = NULO;

Otros

{

Pb nodo =(PBinTreeNode)malloc(sizeof(struct BinTreeNode));

if(pbnode == NULL)

{

printf("¡Espacio insuficiente!\n ");

Devolver pbnode

}

Pb nodo-& gt; info = I;

Nodo Pb->llink = Create_BinTree();

Nodo Pb->rlink = Create_BinTree();

}

Devolver pbnode

}

árbol de salida nulo (nodo PBinTreeNode Pb, int totalSpace)

{ int I

if(pbnode!=null)

{

espacio total+= 5;

Árbol de salida (nodo Pb-& gt; rlink, espacio total);

for(I = 0;i<total space;i++)printf(" ");

printf("%c\n ",Pb nodo->info);

Árbol de salida (nodo Pb->llink, espacio total);

}

}

reserva nula (PBinTreeNode pbnode)

{

if (pbnode==NULL) devuelve;

printf("%c\t ", Pb node->info);

Suscripción (nodo Pb->llink);

Suscripción (nodo Pb->rlink);

}

anular en orden(pbintrenode nodo Pb)

{

if(pbnode== NULL) devuelve;

en orden( Pb node-& gt; llink);

printf("%c\t ", Pb nodo-& gt;info);

en orden(Pb nodo-& gt; rlink);

}

pedido de publicación nulo (nodo pbintrenode Pb)

{

if(pbnode == NULL) regresa

pedido de publicación (nodo Pb->llink; );

publicar pedido(Pb nodo->rlink);

printf("%c \t ", Pb nodo-> info);

}

Hoja vacía (PBinTreeNode)

{

if( Pb nodo->Enlace! = NULL & amp& ampPb nodo->rlink == NULL)

leaf(Pb nodo->llink);

if(Pb nodo->rlink! = NULL & amp& ampPb nodo->llink == NULL)

leaf(Pb nodo->rlink);

if(Pb nodo->link ! = NULL && ampPb nodo- >renlace! =nulo)

{

Hoja(Pb nodo->llink);

Hoja(Pb nodo->rlink);

}

if (Pb nodo->llink == NULL & amp& ampPb nodo->rlink == NULL)

{

printf("%c\t ", Pb nodo-> ;info);

Regresar;

}

}

anular todos los nodos (nodo PBinTreeNode Pb)

{

if(Pb nodo-& gt; Enlace! = NULL & amp& ampPb nodo-& gt; rlink == NULL)

freeall nodos( Pb nodo-& gt; llink);

if(Pb node-& gt;rlink!= NULL & amp& ampPb node-& gt;llink == NULL)

freeall nodos (Pb node-> rlink);

if (Pb nodo->link!= NULL & amp& ampPb nodo->rlink!=null)

{

libretodos los nodos (Pb node->llink);

freeall nodes(Pb node->rlink);

}

if(Pb node-> llink == NULL & amp& ampPb nodo-& gt;rlink == NULL)

{

free(Pb nodo-& gt;llink);

Gratis (Pb nodo->rlink);

pbnode = NULL

Retorno;

}

}

int main()

{ PBinTree pbtree

int I;

int espacio total = 0

printf("Por favor ingrese char en el árbol binario, @Salga del nodo actual:\ n ");

Pb tree = Create _ bintree root();

printf("Mostrar datos del árbol binario directamente : \ n ");

outputTree(*pbtree, espacio total);

printf("Seleccione el árbol binario que desea ejecutar Modo:\ n ");

printf(" 1 . mostrar 2 . reservar 3 . en orden 4 . publicar orden 5 . deja 6 . nodos libres 0 para salir:"); &I);

while(I>6||i<0)

{

printf( "\nSu selección no es válida, vuelva a ingresar:\n ");

printf(" 1 . mostrar 2 . reservar 3 . en orden 4 . publicar pedido 5 . deja 6 . nodos libres 0 para salir: ");

scanf( "%d ", & ampI);

}

Y (yo! =0)

<

p>{

while(I>6||I<0)

{

printf("\nSu elección es ilegal, vuelva a ingresar:\ n ");

printf(" 1 . mostrar 2 . reservar 3 . en orden 4 . publicar pedido 5 . deja 6 . nodos libres 0 para salir:");

scanf( "%d ", & ampI);

}

Y (i!=0)

{

mientras(I> 6||I<0)

{

printf("\nSu selección es ilegal, vuelva a ingresar:\n");

printf(" 1 . mostrar 2 . reservar 3 en orden 4 . publicar pedido 5 . p>}

Y (I! = 6)

{

mientras(I & gt; 6 | |I<0)

{

printf(" \nSu selección es ilegal, vuelva a ingresar:\n ");

printf(" 1. mostrar 2. reservar 3. en orden 4. publicar orden 5. deja 6. nodos libres 0 para salir:");

scanf("%d ",& ampI);

}

Cambiar ( 1)

{

Caso 0:

printf("\nUtilice el último trabajo para liberar todos los nodos...\ n "); >

freeall nodes(* Pb tree);

printf("Todos los nodos se han liberado correctamente\ n ");

Salir(1);

getch();

Caso 1:

printf("\nMostrar árbol binario:\n");

outputTree(*pbtree, espacio total );

Pausa;

Caso 2:

printf("\ndata primer pedido: \ n "); * Pb árbol);

printf(" \ n \ n ");

Romper

Caso 3:

printf( "\ n datos en orden:\ n ");

en orden(* árbol Pb);

printf(" \ n \ n "

Break;

Caso 4:

printf(" \ n Datos en orden de publicación:\ n ");

printf(" \ n \ n ");

Romper

Caso 5:

printf(" \ n hojas: \ n ");

Hojas (*Pb árbol);

printf(" \ n \ n ");

}

printf("Seleccione el modo en el que desea que se ejecute el árbol binario:\ n ");

printf(" 1. mostrar 2 . reservar 3 . en

orden 4 . publicar orden 5 . deja 6 nodos libres 0 para salir: ");

scanf("%d ", & ampI);

}

If (i==6)

{

printf("\nLiberar todos los nodos:\n");

freeall nodes(* Árbol Pb );

printf("Todos los nodos se han liberado exitosamente.");

}

printf("\n\nAhora cree un nuevo árbol binario. ..\ n ");

printf("Por favor, ingrese char en el árbol binario, @Salga del nodo actual:\ n ");

Pb tree = Crear _ bintree root ();

printf("Mostrar directamente los datos del árbol binario:\ n ");

outputTree(*pbtree, espacio total);

printf(" Seleccione el modo en el que desea que se ejecute el árbol binario:\n ");

printf(" 1 . mostrar 2 . reservar 3 . en orden 4 . publicar orden 5 . hojas 6 . nodos libres 0 para salir:" );

scanf("%d ", & ampI);

}

}

printf( "\nUtilice el último trabajo A para liberar todos los nodos\n ");

freeall nodes(* Pb tree);

printf("Todos los nodos se han liberado correctamente\n " );

getch();

Devuelve 0;

}