Código
//********************************************************************/ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> //********************************************************************// //********************************************************************// #define TRUE 1 #define FALSE 0 #define ENTER 13 #define ESC 27 #define ESPACIO 32 #define A 65 #define Z 90 #define N 5000 //********************************************************************// //********************************************************************// typedef struct nombre{ char nombre[30]; char appat[30]; char apmat[30]; }Tnombre; typedef struct alumnos{ Tnombre NombC; long matri; int sexo; }Talum; //********************************************************************// void menu(void); Talum LlenarAut(Talum reg, long vect[], int pos); void ImprimirVect(Talum vect[], int tam); void Imprimir(Talum reg[], int pos); int BusqSec(Talum vect[], int tam, long matri); int BusquedaBin(Talum vect[], int tam, long matri); void OrdenacionShell(Talum vect[], int tam); void LlenarVect(long vect[], int tam, long ri, long rf); int Buscar(long vect[], int tam, long matri); int main(void){ menu(); return 0; } //********************************************************************// void menu(void) { int op, i, j=0, x, pos=0, lleno=FALSE, orde=FALSE; long mat[N], matri; Talum reg, temp, vect[N]; LlenarVect(mat, N, 300000, 399999); do{ switch(op) { case 1: if(j<N) { lleno=TRUE; if(j<400) { for(i=0; i<4000; i++) { temp=LlenarAut(reg, mat, pos); vect[j]=temp; j++; pos++; } } else { for(i=0; i<10; i++) { temp=LlenarAut(reg, mat, pos); vect[j]=temp; j++; pos++; } orde=FALSE; } } else { } break; case 2: if(lleno==TRUE) { if(orde==TRUE) { x=BusquedaBin(vect, j, matri); if(x!=-1) { Imprimir(vect, x); } else { } } else { x=BusqSec(vect, j, matri); if(x!=-1) { Imprimir(vect, x); } else { } } } else { } // system("pause"); break; case 3: if(lleno==TRUE) { if(orde==FALSE) { OrdenacionShell(vect, j); orde=TRUE; } else { } } else { } break; case 4: ImprimirVect(vect, j); break; } }while(op!=5); } Talum LlenarAut(Talum reg, long vect[], int pos) { // Talum reg; int x=0; char NombreH[40][40]={"LUIS","ALBERTO","HUGO","PEDRO","JUAN","JOSE","GOKU","GOHAN","MIGUEL","ANGEL", "DIEGO","RAUL","ROBERTO","MARIO","RAFAEL","JAVIER","CARLOS","ARTURO","EMILIANO","ENRIQUE", "FRANCISCO","RONALDO","PAUL","OSVALDO","SANTIAGO","THIAGO","ESTEBAN","NOEL","LEONEL","MARTIN", "SAMUEL", "LUCAS", "MARCOS", "XAVI","ALONSO","RICARDO", "OMAR", "RENATO", "JONATHAN", "RUBEN"}; char NombreM[40][40]={"EMILY","JASMIN","LUCERO","NICOL","MARIA","CARMEN","ROCIO","CASANDRA","YESICA","VERONICA", "PAOLA","KAREN","ALEJANDRA","ALEXANDRA","ENID","EDITH","CARLA","KARLA","FABIOLA","YOHANA", "MONICA","JENIFER","LUCIA","KIMBERLY","AMANDA","PAULA","PERLA","MIA","STHEPHANIE","ALONDRA", "CLEOPATRA","ANA","CLARA","DIANA","FRIDA","HELENA","JENA","LUCIA","NADIA","SILBIA"}; char Apellidos[40][40]={"PEREZ","LOPEZ","SANCHEZ","FERNANDEZ","MARQUEZ","ESPINOZA","RAMIREZ","PACHECO","PALCIOS","DONARUMA", "DIAZ","PERALTA","AGUILAR","ALLI","ARTETA","ALARCON","DRAXLER","CAZORLA","SANTOS","JIMENEZ", "VIDAL","CISNEROS","MARCHESIN","SAMUDIO","TREJO","RAMOS","MARQUISIO","BONAVENTURA","ASENSIO","MODRIC", "ETO", "ASENSIO", "VELA", "LAINEZ", "SAMBUEZA", "VOLPI", "IBARRA", "LEON", "SUAREZ", "VIETO"}; reg.sexo=x; if(x==1) { } else { } reg.matri=vect[pos]; return reg; } void ImprimirVect(Talum vect[], int tam) { int i=0, j, tecla; do{ printf("\t|----------------------------------------------------------------------------------------------|\n"); printf("\n\t|----------------------------------------------------------------------------------------------|"); for(j=0; j<40 && i<tam; j++, i++) { printf("\n\t|%5d | %-18s | %-18s | %-18s | %-8ld | %-3d |", i+1, vect[i].NombC.appat, vect[i].NombC.apmat, vect[i].NombC.nombre, vect[i].matri, vect[i].sexo); } printf("\n\t|----------------------------------------------------------------------------------------------|"); printf("\n\t|----------------------------------------------------------------------------------------------|"); }while(i<tam && tecla!=ESC); } void Imprimir(Talum reg[], int pos) { } int BusqSec(Talum vect[], int tam, long matri) { int i; for(i = 0; i < tam; i++) { if(vect[i].matri == matri) { return i; } } return -1; } int BusquedaBin(Talum vect[], int tam, long matri) { int central, bajo, alto; int valorcentral; bajo=0; alto=tam-1; while(bajo <= alto) { central = (bajo+alto)/2; valorcentral = vect[central].matri; if(matri == valorcentral) { return central; } else { if(matri < valorcentral) { alto=central-1; } else { bajo=central+1; } } } return -1; } void OrdenacionShell(Talum vect[], int tam) { int intervalo, i, j , k; intervalo = tam/2; while(intervalo > 0) { for(i = intervalo; i < tam; i++) { j=i-intervalo; while(j >= 0) { k=j+intervalo; if(vect[j].matri<=vect[k].matri) { j=-1; } else { Talum temp; temp=vect[j]; vect[j]=vect[k]; vect[k]=temp; j-=intervalo; } } } intervalo=intervalo/2; } } void LlenarVect(long vect[], int tam, long ri, long rf) { int i=0,x; long num; do{ x=Buscar(vect, tam, num); if(x == -1) { vect[i]=num; i++; } }while(i<tam); // return vect; } int Buscar(long vect[], int tam, long matri) { int i; for(i = 0; i < tam; i++) { if(vect[i] == matri) { return i; } } return -1; }
· Los códigos deben ir en etiquetas GeSHi
>aquí las reglas del foro
-Engel Lex