Título: ordenamieno burbuja
Publicado por: sleepy.lito en 12 Diciembre 2018, 23:12 pm
Necesito que mi programa ingrese unos datos a una base y las ordene mediante ordenamiento burbuja, el problema es que no me ordena los libros ingresados, si alguien me pudiese señalar donde tenga el error el prgrama porfavor. Adjunto mi codigo: #include <stdio.h> #include <string.h> #include <conio.h> #define MAXLIN 80 #define MAXTIT 40 #define MAXAUT 40 #define MAXEDIT 40 #define MAXREV 40 #define MAXTXT 100 enum {anadir=1, listartodo, listarano, salir}; struct texto { char titulo[MAXTIT]; char autor[MAXAUT]; char editorial[MAXEDIT]; char revista[MAXREV]; int numref; int numed; int auxref; int anyo; int clase; }; struct biblioteca { struct texto txt[MAXTXT]; int cantidad; }; int main (void) { struct biblioteca mistxt; int opcion, opc, i, j, ano, aux; char titulo[MAXTIT]; char autor[MAXAUT]; char linea[MAXLIN]; mistxt.cantidad = 0; do{ do{ printf("-------------------------------------\n"); printf("Biblioteca Universidad de Valparaisio\n"); printf("-------------------------------------\n"); printf("1) Anadir Libro/Revista.\n"); printf("2) Listar todos los textos.\n"); printf("3) Listar por ano.\n"); printf("Elija una opcion: \n"); if (opcion<1 || opcion>5){ printf("La opcion ingresada es incorrecta, intente otra vez.\n"); } } while (opcion <1 || opcion >5); switch (opcion) { case anadir: if (mistxt.cantidad == MAXTXT) { printf("La base de datos esta llena. Lo sentimos.\n"); } else { printf("Ingrese el numero de referencia: \n"); gets(linea ); sscanf(linea , "%d", &mistxt. txt[mistxt. cantidad]. numref); mistxt.txt[mistxt.cantidad].auxref = mistxt.txt[mistxt.cantidad].numref; printf("Ingrese el titulo: \n"); gets(mistxt. txt[mistxt. cantidad]. titulo); printf("Ingrese el autor: \n"); gets(mistxt. txt[mistxt. cantidad]. autor); printf("Ingrese la editorial: \n"); gets(mistxt. txt[mistxt. cantidad]. editorial); printf("Ingrese ano de publicacion: \n"); gets(linea ); sscanf(linea , "%d", &mistxt. txt[mistxt. cantidad]. anyo); do{ printf("Ingrese la clase de texto que es: \n1) Libro \n2) Revista\n"); printf("Elija la opcion: 1 o 2\n"); if (opc<1 || opc>2){ printf("La opcion ingresada es incorrecta, intente otra vez.\n"); } } while (opcion <1 || opcion >2); switch (opc) { case 1: mistxt.txt[mistxt.cantidad].clase= 1; printf("Ingrese el numero de edicion: \n"); gets(linea ); sscanf(linea , "%d", &mistxt. txt[mistxt. cantidad]. numed); break; case 2: mistxt.txt[mistxt.cantidad].clase= 2; printf("Ingrese el nombre de la revista: \n"); gets(mistxt. txt[mistxt. cantidad]. revista); break; } for(i=0;i<mistxt.cantidad;i++){ for(j=0;j<mistxt.cantidad;j++){ if(mistxt.txt[j].auxref>mistxt.txt[j+1].auxref){ aux = mistxt.txt[j].auxref; mistxt.txt[j].auxref = mistxt.txt[j+1].auxref; mistxt.txt[j+1].auxref=aux; } } } mistxt.cantidad++; } break; case listartodo: for (i=0; i<mistxt.cantidad; i++){ printf("---------------------------\n"); printf("Numero de referencia: %d\n", mistxt. txt[i ]. numref); printf("Titlulo: %s\n", mistxt. txt[i ]. titulo); printf("Autor: %s\n", mistxt. txt[i ]. autor); printf("Editorial: %s\n", mistxt. txt[i ]. editorial); printf("Año de publicacion; %d\n", mistxt. txt[i ]. anyo); if(mistxt.txt[i].clase == 1){ printf("Tipo de texto: Libro\n"); printf("N° de edicion: %d\n", mistxt. txt[i ]. numed); } if(mistxt.txt[i].clase == 2){ printf("Tipo de texto: Revista\n"); printf("Nombre de la revista: %s\n", mistxt. txt[i ]. revista); } printf("---------------------------\n"); } break; case listarano: printf("Ingrese el ano a buscar: \n"); for (i=0; i<mistxt.cantidad; i++){ if (mistxt.txt[i].anyo==ano){ printf("---------------------------\n"); printf("Numero de referencia: %d\n", mistxt. txt[i ]. numref); printf("Titlulo: %s\n", mistxt. txt[i ]. titulo); printf("Autor: %s\n", mistxt. txt[i ]. autor); printf("Editorial: %s\n", mistxt. txt[i ]. editorial); printf("Año de publicacion; %d\n", mistxt. txt[i ]. anyo); if(mistxt.txt[i].clase == 1){ printf("Tipo de texto: Libro\n"); printf("N° de edicion: %d\n", mistxt. txt[i ]. numed); } if(mistxt.txt[i].clase == 2){ printf("Tipo de texto: Revista\n"); printf("Nombre de la revista: %s\n", mistxt. txt[i ]. revista); } printf("---------------------------\n"); } } break; } } while (opcion != salir); return 0; }
Título: Re: ordenamieno burbuja
Publicado por: K-YreX en 13 Diciembre 2018, 00:12 am
El código entre etiquetas GeSHi. Se seleccionan encima del cuadro de texto que aparece cuando escribes un mensaje, donde pone "Código GeSHi". Después igual podemos ayudarte... :-X
Título: Re: ordenamieno burbuja
Publicado por: CalgaryCorpus en 13 Diciembre 2018, 16:41 pm
No parece haber codigo que compare y de vuelta libros. Veo un codigo que compara y da vuelta auxref dentro de libros, pero no libros. Siendo asi, los libros no se van a ordenar.
|