Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* EDD: tarea 2 */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- /* Estructuras; de específico a global */
- typedef struct pallet
- {
- int altura; /* Altura referencial del pallet */
- int egreso; /* Fecha de egreso, en caso de no tener, valor = 0 */
- int id; /* Valor asociado para identificar el pallet */
- struct pallet *sig; /* Siguiente pallet de la pila */
- }tPallet;
- typedef struct pila
- {
- int maxAltura; /* Altura máxima */
- int alturaActual; /* Altrura actual */
- int posPila; /* Posición de la pila dentro de la bodega 0 a 335 */
- tPallet caja;
- }tPila;
- typedef struct colaEnvios /* cola de envios xD */
- {
- tPallet cajaEnvio;
- struct colaEnvios *sig;
- }tCola;
- typedef struct bodega
- {
- tPila arregloPilas[335]; /* Arreglo de tipo tPilas, 0 a 335 pilas en total */
- int numeroBodega; /* número de 0 a 99 */
- struct bodega *sig; /* Apunta a la siguiente bodega, de un total de 100 */
- }tBodega;
- typedef struct listaD /* Lista de registro, doblemente enazada */
- {
- int altura;
- int egreso;
- int id;
- int numeroBodega;
- int numeroPila;
- struct listaD *sig;
- struct listaD *ant;
- }tLista;
- /* Algoritmos con pilas y colas */
- /* PILAS */
- tPallet *crearPallet(int altura, int egreso, int id) /* Para ir probando nuestros algoritmos junto con imprimir */
- {
- tPallet *nuevo ;
- nuevo=(tPallet *)malloc(sizeof(tPallet));
- nuevo->altura=altura;
- nuevo->egreso=egreso;
- nuevo->id=id;
- return nuevo;
- }
- void apilar(tPila **frente, tPallet *nuevo, tBodega *bodegas)
- {
- int i,j=0;
- tPallet *aux = NULL;
- while (bodegas != NULL) /* Recorremos las bodegas */
- {
- (*bodegas).numeroBodega = j; /* */
- for (i=0; i<335; i++)
- {
- **frente = bodegas->arregloPilas[i];
- (*frente)->maxAltura = 8;
- (*frente)->posPila = i;
- if(((*frente)->alturaActual + (*nuevo).altura <= 8) && ((*frente)->caja.id != (*nuevo).id))
- {
- (*frente)->alturaActual = (*frente)->alturaActual + (*nuevo).altura;
- if (*frente == NULL)
- {
- (*frente)->caja=*nuevo;
- }
- if((*frente)->caja.sig == NULL)
- {
- (*frente)->caja.sig=nuevo;
- }
- else
- {
- *aux = (*frente)->caja;
- while (aux->sig != NULL)
- {
- aux=aux->sig;
- }
- aux->sig=nuevo;
- }
- }
- else
- printf ("Bodegas llenas o id repetida");
- }
- }
- j++;
- bodegas = bodegas->sig;
- }
- tPallet *desapilar(tPila **frente, tBodega *bodegas, tPallet porDesapilar)
- {
- tPallet *aux;
- tPallet *aux2 = NULL;
- int i;
- while (bodegas != NULL)
- {
- for (i=0; i<335; i++)
- {
- **frente = bodegas->arregloPilas[i];
- if (*frente == NULL)
- {
- return NULL;
- }
- else if ((*frente)->caja.id == porDesapilar.id)
- {
- *aux=(*frente)->caja;
- (*frente)->caja=*((*frente)->caja.sig);
- return aux;
- }
- else
- {
- printf("No se encontraba el pallet");
- }
- }
- bodegas = bodegas->sig;
- }
- return aux2;
- }
- int esVaciaPila(tPila *frente)
- {
- if (frente==NULL)
- {
- return 1;
- }
- return 0;
- }
- /* COLAS */
- void encolar(tCola **frente, tPallet *nuevo, int contador)
- {
- if (*frente==NULL)
- {
- *frente=(tCola*)malloc(sizeof(tCola));
- (*frente)->cajaEnvio = *nuevo;
- (*frente)->sig = NULL;
- }
- else if (contador<500)
- {
- while ((*frente != NULL) )
- {
- contador+=1;
- *frente=(*frente)->sig;
- }
- *frente=(tCola*)malloc(sizeof(tCola));
- (*frente)->cajaEnvio = *nuevo;
- (*frente)->sig= NULL;
- }
- else
- printf("Cola en espera para mañana");
- }
- tCola *desencolar(tCola **frente)
- {
- tCola*aux=NULL;
- aux=*frente;
- if (*frente != NULL){
- *frente=(*frente)->sig;
- aux->sig = NULL;
- return aux;
- }
- else{
- *frente = NULL;
- return aux;
- }
- }
- int esVaciaCola(tCola**frente)
- {
- if (*frente==NULL)
- {
- return 1;
- }
- return 0;
- }
- int main()
- {
- /* aca comienza la lectura de archivos*/
- char cadena[100],*i="i",*g="g",*a="a",*r="r",*e="e",*c="c";
- char alt[1];
- int altura,plazo,identificador,egreso;
- char ident[6],egr[6];
- FILE *input;
- input = fopen("input.dat","r");
- while(!feof(input))
- {
- fgets(cadena, 300, input);
- {
- if(cadena[2]==*i)
- {
- /* iniciar dia */
- }
- if(cadena[2]==*g)
- {
- /* aca se recopilan las variables todas como int */
- alt[0] = cadena[26];
- altura = atoi(alt);
- plazo = cadena[35] - 48;
- ident[0] = cadena[12];
- ident[1] = cadena[13];
- ident[2] = cadena[14];
- ident[3] = cadena[15];
- ident[4] = cadena[16];
- identificador = atol(ident);
- }
- if(cadena[2]==*a)
- {
- /*siguiente dia*/
- }
- if(cadena[2]==*r)
- {
- /*se divide en 2 para simplificar*/
- if(cadena[0]==*e)
- {
- egr[0] = cadena[11];
- egr[1] = cadena[12];
- egr[2] = cadena[13];
- egr[3] = cadena[14];
- egr[4] = cadena[15];
- egreso = atol(egr);
- }
- if(cadena[0]==*c)
- {
- fclose(input);
- }
- }
- }
- }
- return (0);
- }
Add Comment
Please, Sign In to add comment