/* Ordena un fichero de pedidos utilizando una tabla índice */ #include #include typedef struct{ char codcli[7]; char codart[7]; char fecha[9]; short unidades; }TIPOPEDIDO; typedef struct { char clave[7]; long posicion; } ElementoIdx; ElementoIdx TablaIndex[1000]; // Tabla indice TIPOPEDIDO reg; FILE *pped; FILE *pord; int numped=0; int AbrirFicheros() { pped=fopen("Pedidos.dat","r"); pord=fopen("Pedord.dat","w"); if ((pped==NULL)||(pord==NULL)) { return 0; } else { return 1; } } void CargarTabla() { int i=0; fread(& reg,sizeof(TIPOPEDIDO),1 ,pped); while (!feof(pped)) { if (reg.unidades!=0) { strcpy(TablaIndex[numped].clave,reg.codcli); // Guardo la posición relativa: El nº de registro en el fichero TablaIndex[numped].posicion = i; numped++; } i++; fread(& reg,sizeof(TIPOPEDIDO),1,pped); } } /* Ordenación por el método de selección directa */ void OrdenarTabla() { int i,j; ElementoIdx min; int posmin; for(i=0;i