Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- typedef struct
- {
- int idAlumno;
- char alumno[20];
- struct nodoArbol1 *izq;
- struct nodoArbol1 *der;
- struct nodoArbol2 *abdab;
- } nodoArbol1;
- typedef struct
- {
- char asignatura[20];
- int nota;
- char estadoCursada[15]; ///activo - inactivo
- } stMateriaYNota;
- typedef struct
- {
- stMateriaYNota MyN;
- struct nodoArbol2 *izq;
- struct nodoArbol2 *der;
- } nodoArbol2;
- nodoArbol1 *inicArbol1();
- nodoArbol2 *inicArbol2();
- nodoArbol1 *crearNodoArbol1(int idAlumno, char alumno[]);
- nodoArbol2 *crearNodoArbol2(stMateriaYNota MyN);
- stMateriaYNota auxCarga(char asignatura[], int nota, char estadoCursada[]);
- nodoArbol1 *agregarAlArbol1(nodoArbol1 *lito, nodoArbol1 *nn);
- nodoArbol2 *agregarAlArbol2(nodoArbol2 *lito2, nodoArbol2 *nn);
- nodoArbol1 *altaEnAbdAb(int idAlumno, char alumno[],stMateriaYNota MyN, nodoArbol1 *lito);
- void recorrerYMostrarAbl(nodoArbol1 *lito);
- void mostrarArbol1(nodoArbol1 *lito);
- void mostrarArbol2(nodoArbol2 *lito2);
- int main()
- {
- nodoArbol1 *lito = inicArbol1();
- stMateriaYNota aux;
- aux = auxCarga("Matematica", 8, "Activo");
- lito = altaEnAbdAb(3, "Jose", aux, lito);
- /*
- aux = auxCarga("Contabilidad", 2, "inactivo");
- lito = altaEnAbdAb(3, "Jose", aux, lito);
- aux = auxCarga("Programacion", 9, "activo");
- lito = altaEnAbdAb(1, "Ale", aux, lito);
- aux = auxCarga("Metodologia", 4, "inactivo");
- lito = altaEnAbdAb(2, "Miguel", aux, lito);
- aux = auxCarga("Programacion", 9, "activo");
- lito = altaEnAbdAb(2, "Miguel", aux, lito);
- */
- recorrerYMostrarAbl(lito);
- return 0;
- }
- nodoArbol1 *inicArbol1()
- {
- return NULL;
- }
- nodoArbol2 *inicArbol2()
- {
- return NULL;
- }
- nodoArbol1 *crearNodoArbol1(int idAlumno, char alumno[])
- {
- nodoArbol1 *aux = (nodoArbol1*) malloc(sizeof(nodoArbol1));
- aux->idAlumno = idAlumno;
- strcpy(aux->alumno, alumno);
- aux->izq = NULL;
- aux->der = NULL;
- aux->abdab = inicArbol2();
- return aux;
- }
- nodoArbol2 *crearNodoArbol2(stMateriaYNota MyN)
- {
- nodoArbol2 *aux = (nodoArbol2*) malloc (sizeof(nodoArbol2));
- aux->MyN = MyN;
- aux->izq = NULL;
- aux->der = NULL;
- return aux;
- }
- stMateriaYNota auxCarga(char asignatura[], int nota, char estadoCursada[])
- {
- stMateriaYNota aux;
- strcpy(aux.asignatura, asignatura);
- aux.nota = nota;
- strcpy(aux.estadoCursada, estadoCursada);
- return aux;
- }
- nodoArbol1 *agregarAlArbol1(nodoArbol1 *lito, nodoArbol1 *nn)
- {
- if(lito == NULL)
- {
- lito = nn;
- }
- else if (nn->idAlumno < lito->idAlumno)
- {
- lito->izq = agregarAlArbol1(lito->izq, nn);
- }
- else
- {
- lito->der = agregarAlArbol1(lito->der, nn);
- }
- return lito;
- }
- nodoArbol2 *agregarAlArbol2(nodoArbol2 *lito2, nodoArbol2 *nn)
- {
- if(lito2 == NULL)
- {
- lito2 = nn;
- }
- else if(nn->MyN.nota < lito2->MyN.nota)
- {
- lito2->izq = agregarAlArbol2(lito2->izq, nn);
- }
- else
- {
- lito2->der = agregarAlArbol2(lito2->der, nn);
- }
- return lito2;
- }
- nodoArbol1 *altaEnAbdAb(int idAlumno, char alumno[],stMateriaYNota MyN, nodoArbol1 *lito)
- {
- nodoArbol2 *nn2 =crearNodoArbol2(MyN);
- if(lito == NULL) ///si el arbol es null ingreso el alumno, y al mismo le agrego sus respectivos datos
- {
- nodoArbol1 *nn = crearNodoArbol1(idAlumno, alumno);
- lito = agregarAlArbol1(lito, nn);
- nodoArbol2 *lito2 = lito->abdab;
- lito->abdab = agregarAlArbol2(lito2, nn2);
- }
- else
- {
- if(lito->idAlumno == idAlumno) /// si el arbol no es NULL recorro recursivamente, y busco si ya se encuentra el id, y agrego los datos
- {
- nodoArbol2 *lito2 = lito->abdab;
- lito->abdab = agregarAlArbol2(lito2, nn2);
- }
- else if (lito->idAlumno < idAlumno)
- {
- lito->izq = altaEnAbdAb(idAlumno, alumno, MyN, lito->izq);
- }
- else if((lito->idAlumno > idAlumno))
- {
- lito->der = altaEnAbdAb(idAlumno, alumno, MyN, lito->der);
- }
- else ///el arbol no es NULLO, y no se encuentra el dato, entonces lo creo y agrego
- {
- nodoArbol1 *nn = crearNodoArbol1(idAlumno, alumno);
- lito = agregarAlArbol1(lito, nn);
- }
- }
- return lito;
- }
- void recorrerYMostrarAbl(nodoArbol1 *lito)
- {
- if(lito != NULL)
- {
- mostrarArbol1(lito);
- //aca habia un error de tipo
- nodoArbol2 *lito2 = lito->abdab;
- if(lito2 != NULL)
- {
- mostrarArbol2(lito2); //modularizo completamente como mostrar otro arbol
- }
- recorrerYMostrarAbl(lito->izq);
- recorrerYMostrarAbl(lito->der);
- }
- }
- void mostrarArbol1(nodoArbol1 *lito)
- {
- printf("\nidAlumno......: [%d]", lito->idAlumno);
- printf("\nAlumno........: [%s]", lito->alumno);
- printf("\n --");
- }
- void mostrarArbol2(nodoArbol2 *lito2)
- {
- if (lito2!=NULL)
- {
- //muestro los datos de ese nodo
- printf("\nAsignatura.....:[%s]", lito2->MyN.asignatura);
- printf("\nNota...........:[%d]", lito2->MyN.nota);
- printf("\nEstadoCurs.....:[%s]", lito2->MyN.estadoCursada);
- printf("\n-------");
- //llamado recursivc para moverme dentro del arbol
- mostrarArbol2(lito2->der);
- mostrarArbol2(lito2->izq);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment