int main()
{
int n,i,j,z,q,w,aw,d;
int t=0,sw=0;
printf("\n Enter number of prosesses:");
scanf("%d",&n);
printf("\n Enter arrival times sorted assendings:");
for (i=1;i<=n;i++)
{
printf("\n");
scanf("%d,%t",&array1);
}//end of for
printf("\n enter execution time prosesses:");
for(i=1;i<=n;i++)
{
printf("\n");
scanf("%d",&array2);
z=array2;
qstore(z);
}//end of for
printf("\n enter timequantum:");
scanf("%d",&q);
for(;
{
if((z=retrive())!=NULL)
{
if (z<=q)
{
j=i;
z=z-z;
t=t+z;
w=t-z-array2[j];
printf("\n wait time prosess%d=%d",j,w);
sw+=w;
}
if(z>q)
{
d=i;
z=z-q;
t=t+z;
qstore(z);
}
}getch();
}
aw=w/n;
printf("average wait time=%d",aw);
getch();
}
//**
void qstore(int a)
{
if((spos+1==rpos)||(spos+1==max && !rpos))
{
printf("\n list is full.");
getch();
return;
}//end of if
buf[spos]=a;
spos++;
if(spos==max)
spos=0;
}
//**
int retrive()
{
if(rpos==max)
rpos=1;
if(rpos==spos)
{
printf("\nqueue is empty.");
return NULL;
}
rpos++;
return buf[rpos-1];
}