I have a program that simulates FIFO. My professor says I need to add to the head and then move it to the tail not add directly to the tail which he says is what I am doing. I am having difficulty with this. Can anyone help. My code entire code follows, the function addQ is where the replacement takes place.
# include<conio.h>
# include<stdlib.h>
# include <time.h>
struct CQueue
{
int head;
int tail;
int Values[10];
} Ob_queue;
int isFull()
{
if(Ob_queue.tail-Ob_queue.head >= 10)
return 1;
return 0;
}
void AddQ(int value)
{
if (isFull ())
RemoveQ();
Ob_queue.Values[Ob_queue.tail++]=value;
printf("%d\n", Ob_queue.tail-Ob_queue.head);
}
int RemoveQ ()
{
if(Ob_queue.head != Ob_queue.tail)
return Ob_queue.Values[Ob_queue.head++];
return -1;
}
int TopQ ()
{
if(Ob_queue.head != Ob_queue.tail)
return Ob_queue.Values[Ob_queue.head];
return -1;
}
void Init ()
{
Ob_queue.head=0;
Ob_queue.tail=0;
}
int isPresent (int value)
{
int i=0;
for(i=Ob_queue.head; i<Ob_queue.tail; i++)
if(value == Ob_queue.Values[i])
return 1;
return 0;
}
int main()
{
int PageFaults=0, value=0, i, Rands[40], count=0;
Init();
srand(time(0));
for (i=0; i<40; i++)
{
value = rand()%20;
if (!isPresent(value))
{
printf("Process %d", value);
printf(" recieves Page Frame ");
PageFaults++;
AddQ(value);
printf("\t");
}
Rands[count++]=value;
}
printf("\n\nThere were ");
printf("%d", PageFaults);
printf(" Page Faults\n\nReference String:\n\n");
for(i=0; i<40; i++)
{
printf("%d", Rands[i]);
printf("\t");
}
getch();
}