In a (very) straightforward implementation, you replace the array of
float
with an array of
OrdenPizza
. A show you a replacement for the
agrega
function:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 10
struct OrdenPizza
{
char cliente[200];
char nombre[200];
int cantidad;
int precioUnitario;
int monto;
};
struct Cola
{
int p, u;
struct OrdenPizza op[MAX];
};
void iniciaCola(struct Cola *c)
{
c->p = -1;
c->u = -1;
}
int agrega(struct Cola *c, const struct OrdenPizza * pOP)
{
int k,j;
if (c->p == -1)
{
c->p = c->u = 0;
c->op[0] = *pOP;
return 1;
}
if (c->u==MAX-1)
{
if (c->p != 0)
{
j=0;
for(k=c->p; k<=c->u; k++)
{
c->op[j] = c->op[k];
j=j+1;
}
c->p=0;
c->u=j-1;
}
else
return 0;
}
c->u = c->u + 1;
c->op[c->u] = *pOP;
return 1;
}
int main()
{
struct Cola cola;
iniciaCola(&cola);
struct OrdenPizza op;
strcpy(op.cliente, "Zorro");
strcpy(op.nombre, "Z27");
op.cantidad = 2;
op.precioUnitario = 4;
agrega( &cola, &op);
struct OrdenPizza * p = &cola.op [cola.u];
printf("%s %s %d %d %d\n", p->cliente, p->nombre, p->cantidad, p->precioUnitario, p->monto);
return 0;
}
In a more efficient approach, your FIFO maintains an array of
pointers to
OrdenPizza struct
instances.