Professional Documents
Culture Documents
h>
#include<stdlib.h>
struct node{
int prnum;
int atime;
int btime;
int wtime;
int tatime;
int xstime;
int xetime;
void BsortLL(NODE*);
void ProcessLL(NODE*);
void PrintLL(NODE*);
void PrintGchart(NODE*);
int main(void)
{
FILE *fp;
NODE *start;
NODE *temp;
NODE *NEW;
int prnum, atime, btime;
start = (NODE*)malloc(sizeof(NODE));
start->ptr = NULL;
temp = start;
fp = fopen("fcfs.data","r");
if( fp == NULL)
{
printf("\nError opening file");
exit(EXIT_FAILURE);
}
while( 1 )
{
fscanf(fp,"%d %d %d",&prnum,&atime,&btime);
if( feof(fp) )
{
break;
}
NEW = (NODE*)malloc(sizeof(NODE));
NEW->ptr = NULL;
NEW->prnum = prnum;
NEW->atime = atime;
NEW->btime = btime;
temp->ptr = NEW;
temp = temp->ptr;
//printf("\n%d\t%d\t%d",NEW->prnum,NEW->atime,NEW->btime);
fclose(fp);
printf("\n");
free(start);
exit(EXIT_SUCCESS);
} //End of main()
temp1 = LL->ptr;
while(temp2 != NULL)
{
if(temp1->atime > temp2->atime)
{
prnum_buf = temp1->prnum;
atime_buf = temp1->atime;
btime_buf = temp1->btime;
temp1->prnum = temp2->prnum;
temp1->atime = temp2->atime;
temp1->btime = temp2->btime;
temp2->prnum = prnum_buf;
temp2->atime = atime_buf;
temp2->btime = btime_buf;
}
temp2 = temp2->ptr;
}
temp1 = temp1->ptr;
}
}
xstime0 = temp->atime;
temp->xstime = xstime0;
xetime0 = xstime0 + temp->btime;
temp->xetime = xetime0;
temp->wtime = 0;
temp->tatime = 0 + temp->btime;
nprocess++;
sigmawt = 0;
sigmatat = temp->tatime;
temp = temp->ptr;
a1 = temp->atime ;
else
{
xstime1 = xetime0;
w1 = xstime1 - a1;
temp->wtime = w1;
temp->tatime = temp->wtime + temp->btime;
xstime0 = xstime1;
xetime0 = xstime0 + temp->btime;
temp->xstime = xstime0;
temp->xetime = xetime0;
nprocess++;
}
printf("\n");
printf("Average waiting time = %3d",sigmawt/nprocess);
printf("\n");
printf("Average turn-around time = %3d",sigmatat/nprocess);
printf("\n");
} //End of ProcessLL()
temp = temp->ptr;
}
printf("\n");
/****PrintGchart()******/
printf("\n\n");
printf("[%d]",temp->xetime);
printf("____");
}
if ( temp->ptr == NULL )
{
printf("[%d]",temp->xetime);
}
temp = temp->ptr;
}
printf("\n\n");