Insert at the beginning of a circular queue
I am working on a circular queue program where I want to implement a "paste queue" function, where the user inserts a number and this number should be inserted into the spaces in the queue prior to f.com. But the logic I implemented did not seem to work very well, I would like to ask for help with ideas or on what to do effectively in the code. I declared my ASSM queue:
struct circular
{ int com;
int fim;
int total;
int memo[MAX];
};
typedef struct circular circular;
int main ()
{
struct circular F;
F.com = 0;
F.total = 0;
F.fim = -1;
}
In this way I declare the queue and initialize it in main, the function I tried create but did not work was this:
void furafila(struct circular *F, int x)
{ int aux,aux2;
aux = F->com;
F->fim++;
if(F->fim == MAX)
{
F->fim = 0;
}
aux2=F->fim;
F->memo[F->fim] = x;
F->com = aux2;
F->fim = aux-1;
F->total++;
}
Any suggestions?
0
Author: Kelvin Huggies, 2018-06-14