Guest User

Untitled

a guest
Jan 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.12 KB | None | 0 0
  1. /* EDD: tarea 2 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. /* Estructuras; de específico a global */
  7.  
  8.  
  9. typedef struct pallet
  10. {
  11. int altura; /* Altura referencial del pallet */
  12. int egreso; /* Fecha de egreso, en caso de no tener, valor = 0 */
  13. int id; /* Valor asociado para identificar el pallet */
  14. struct pallet *sig; /* Siguiente pallet de la pila */
  15. }tPallet;
  16.  
  17. typedef struct pila
  18. {
  19. int maxAltura; /* Altura máxima */
  20. int alturaActual; /* Altrura actual */
  21. int posPila; /* Posición de la pila dentro de la bodega 0 a 335 */
  22. tPallet caja;
  23. }tPila;
  24.  
  25. typedef struct colaEnvios /* cola de envios xD */
  26. {
  27. tPallet cajaEnvio;
  28. struct colaEnvios *sig;
  29. }tCola;
  30.  
  31. typedef struct bodega
  32. {
  33. tPila arregloPilas[335]; /* Arreglo de tipo tPilas, 0 a 335 pilas en total */
  34. int numeroBodega; /* número de 0 a 99 */
  35. struct bodega *sig; /* Apunta a la siguiente bodega, de un total de 100 */
  36. }tBodega;
  37.  
  38. typedef struct listaD /* Lista de registro, doblemente enazada */
  39. {
  40. int altura;
  41. int egreso;
  42. int id;
  43. int numeroBodega;
  44. int numeroPila;
  45. struct listaD *sig;
  46. struct listaD *ant;
  47. }tLista;
  48.  
  49. /* Algoritmos con pilas y colas */
  50.  
  51. /* PILAS */
  52.  
  53. tPallet *crearPallet(int altura, int egreso, int id) /* Para ir probando nuestros algoritmos junto con imprimir */
  54. {
  55. tPallet *nuevo ;
  56. nuevo=(tPallet *)malloc(sizeof(tPallet));
  57. nuevo->altura=altura;
  58. nuevo->egreso=egreso;
  59. nuevo->id=id;
  60. return nuevo;
  61. }
  62.  
  63. void apilar(tPila **frente, tPallet *nuevo, tBodega *bodegas)
  64. {
  65. int i,j=0;
  66. tPallet *aux = NULL;
  67.  
  68. while (bodegas != NULL) /* Recorremos las bodegas */
  69. {
  70. (*bodegas).numeroBodega = j; /* */
  71. for (i=0; i<335; i++)
  72. {
  73. **frente = bodegas->arregloPilas[i];
  74. (*frente)->maxAltura = 8;
  75. (*frente)->posPila = i;
  76. if(((*frente)->alturaActual + (*nuevo).altura <= 8) && ((*frente)->caja.id != (*nuevo).id))
  77. {
  78. (*frente)->alturaActual = (*frente)->alturaActual + (*nuevo).altura;
  79.  
  80. if (*frente == NULL)
  81. {
  82. (*frente)->caja=*nuevo;
  83. }
  84.  
  85. if((*frente)->caja.sig == NULL)
  86. {
  87. (*frente)->caja.sig=nuevo;
  88. }
  89.  
  90. else
  91. {
  92. *aux = (*frente)->caja;
  93. while (aux->sig != NULL)
  94. {
  95. aux=aux->sig;
  96. }
  97. aux->sig=nuevo;
  98. }
  99. }
  100. else
  101. printf ("Bodegas llenas o id repetida");
  102. }
  103. }
  104. j++;
  105. bodegas = bodegas->sig;
  106. }
  107.  
  108.  
  109.  
  110.  
  111. tPallet *desapilar(tPila **frente, tBodega *bodegas, tPallet porDesapilar)
  112. {
  113. tPallet *aux;
  114. tPallet *aux2 = NULL;
  115. int i;
  116.  
  117. while (bodegas != NULL)
  118. {
  119. for (i=0; i<335; i++)
  120. {
  121. **frente = bodegas->arregloPilas[i];
  122.  
  123. if (*frente == NULL)
  124. {
  125. return NULL;
  126. }
  127. else if ((*frente)->caja.id == porDesapilar.id)
  128. {
  129. *aux=(*frente)->caja;
  130. (*frente)->caja=*((*frente)->caja.sig);
  131. return aux;
  132. }
  133. else
  134. {
  135. printf("No se encontraba el pallet");
  136. }
  137.  
  138. }
  139. bodegas = bodegas->sig;
  140. }
  141. return aux2;
  142. }
  143.  
  144. int esVaciaPila(tPila *frente)
  145. {
  146. if (frente==NULL)
  147. {
  148. return 1;
  149. }
  150.  
  151. return 0;
  152.  
  153. }
  154.  
  155.  
  156. /* COLAS */
  157.  
  158. void encolar(tCola **frente, tPallet *nuevo, int contador)
  159. {
  160. if (*frente==NULL)
  161. {
  162. *frente=(tCola*)malloc(sizeof(tCola));
  163. (*frente)->cajaEnvio = *nuevo;
  164. (*frente)->sig = NULL;
  165. }
  166. else if (contador<500)
  167. {
  168. while ((*frente != NULL) )
  169. {
  170. contador+=1;
  171. *frente=(*frente)->sig;
  172. }
  173. *frente=(tCola*)malloc(sizeof(tCola));
  174. (*frente)->cajaEnvio = *nuevo;
  175. (*frente)->sig= NULL;
  176. }
  177. else
  178. printf("Cola en espera para mañana");
  179. }
  180.  
  181. tCola *desencolar(tCola **frente)
  182. {
  183. tCola*aux=NULL;
  184. aux=*frente;
  185. if (*frente != NULL){
  186. *frente=(*frente)->sig;
  187. aux->sig = NULL;
  188. return aux;
  189. }
  190. else{
  191. *frente = NULL;
  192. return aux;
  193. }
  194.  
  195.  
  196. }
  197.  
  198. int esVaciaCola(tCola**frente)
  199. {
  200. if (*frente==NULL)
  201. {
  202. return 1;
  203. }
  204.  
  205. return 0;
  206.  
  207. }
  208. int main()
  209. {
  210. /* aca comienza la lectura de archivos*/
  211.  
  212. char cadena[100],*i="i",*g="g",*a="a",*r="r",*e="e",*c="c";
  213. char alt[1];
  214. int altura,plazo,identificador,egreso;
  215. char ident[6],egr[6];
  216. FILE *input;
  217. input = fopen("input.dat","r");
  218. while(!feof(input))
  219. {
  220. fgets(cadena, 300, input);
  221. {
  222. if(cadena[2]==*i)
  223. {
  224. /* iniciar dia */
  225. }
  226. if(cadena[2]==*g)
  227. {
  228. /* aca se recopilan las variables todas como int */
  229.  
  230. alt[0] = cadena[26];
  231. altura = atoi(alt);
  232. plazo = cadena[35] - 48;
  233. ident[0] = cadena[12];
  234. ident[1] = cadena[13];
  235. ident[2] = cadena[14];
  236. ident[3] = cadena[15];
  237. ident[4] = cadena[16];
  238. identificador = atol(ident);
  239.  
  240. }
  241. if(cadena[2]==*a)
  242. {
  243. /*siguiente dia*/
  244. }
  245. if(cadena[2]==*r)
  246. {
  247. /*se divide en 2 para simplificar*/
  248.  
  249. if(cadena[0]==*e)
  250. {
  251. egr[0] = cadena[11];
  252. egr[1] = cadena[12];
  253. egr[2] = cadena[13];
  254. egr[3] = cadena[14];
  255. egr[4] = cadena[15];
  256. egreso = atol(egr);
  257. }
  258. if(cadena[0]==*c)
  259. {
  260. fclose(input);
  261. }
  262. }
  263. }
  264. }
  265. return (0);
  266. }
Add Comment
Please, Sign In to add comment