Experiment two: Job scheduling simulation Program

Source: Internet
Author: User

#include <stdio.h> #include <stdlib.h>typedef struct process_fcfs{char name;//process name Float arrivetime;//arrival time Float servetime;//service time float finishtime;//completion time float roundtime;//turnaround time float daiquantime;//take right turnaround time struct PROCESS_FCFS * link;//structural body pointer}fcfs;  FCFS *p,*q,*head=null;    struct PROCESS_FCFS a[100]; FCFS inital (struct PROCESS_FCFS a[],int n); void print (struct PROCESS_FCFS a[],int n);  void Fcfs (struct PROCESS_FCFS a[],int n);     struct PROCESS_FCFS *sortarrivetime (struct PROCESS_FCFS a[],int n);   Bubble Sort by arrival time struct PROCESS_FCFS *sortarrivetime (struct PROCESS_FCFS a[],int n) {int i,j;  struct PROCESS_FCFS t;   int flag;    for (i=1;i<n;i++) {flag=0;  for (j=0;j<n-i;j++) {if (a[j].arrivetime>a[j+1].arrivetime) {t=a[j];a[j]=a[j+1];a[j+1]=t;  flag=1;//Exchange}} if (flag==0)//If no interchange occurs in a trip, the sort ends with a break; } return A; }//First come first service algorithm void Fcfs (struct PROCESS_FCFS a[],int n) {int i;a[0].finishtime=a[0].arrivetime+a[0].servetime;a[0].roundtime=a[0].finishtime+a[0].arrivetime;a[0].daiquantime=a[0].roundtime/a[0].servetime;  for (i=0;i<n;i++) {if (a[i].arrivetime>a[i-1].finishtime) {a[i].finishtime=a[i-1].finishtime+a[i].servetime;    A[i].roundtime=a[i].finishtime-a[i].arrivetime;   A[i].daiquantime=a[i].roundtime/a[i].servetime;  }else{A[i].finishtime=a[i].arrivetime+a[i].servetime;  A[i].roundtime=a[i].finishtime+a[i].arrivetime;  A[i].daiquantime=a[i].roundtime/a[i].servetime;  } printf ("First come first service \ n");p rint (a,n); }} void print (struct PROCESS_FCFS a[],int n) {int i;for (i=0;i<n;i++) {printf ("Process name:%c", a[i].name); printf ("On arrival Room:%f ", a[i].arrivetime);   printf ("Service Hours:%f", a[i].servetime);  printf ("Completion time:%f", a[i].finishtime);  printf ("Turnaround time:%f", a[i].roundtime);         printf ("With right turnaround time:%f", a[i].daiquantime);  printf ("\ n");  }}//main function void Main () {int n,i;   printf ("Please enter a few processes \ n");  scanf ("%d", &n);   for (i=0;i<n;i++) {printf ("Print%d process name:", i+1); scanf ("%c", &a[i].name);  printf ("Arrivetime");  scanf ("%f", &a[i].arrivetime);    printf ("Servetime"); scanf ("%f", &a[i].servetime); } Fcfs (A,n);  }

Experiment two: Job scheduling simulation Program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.