Experiment two scheduling

Source: Internet
Author: User

#include <stdio.h> #include <string.h>void main () {int I=0,j=0,finish=0,n=0,k=0,l,m;int start,temp,max=1,    Min,respond[24];int reach[24],running[24];    FILE *FP;    Char filename[100];    Char str[1000];p rintf ("\nenter a filepath/filename:\n");             Gets (filename);    Lost files directory fp=fopen (filename, "RT"),//fp=fopen ("C:/1.txt", "RT"); if (fp==null) {printf ("Cannot open file\n"); return;}    printf ("Time required to arrive \ \ \");        while (Fgets (STR,1000,FP)) {sscanf (str, "%d,%d\n", reach+i,running+i); printf ("%d\t\t%d\n", Reach[i],running[i]); i++;} Fclose (FP); for (j=0;j<i;j++) {for (k=0;k<i-j;k++) {if (reach[k]>reach[k+1]) {temp=running[k];running[k]= RUNNING[K+1]; RUNNING[K+1]=TEMP;TEMP=REACH[K];REACH[K]=REACH[K+1];   Reach[k+1]=temp;} }}printf ("1.fcfs\n2. Sjf\n3. Hrrn\n "), scanf ("%d ", &n), Start=reach[1];if (n==1) {//fcfsprintf (" fcfs\n ");p rintf (" job number start time \ t run time \ t finish time \ t turnaround Time with right turnaround time \ n "); for (j=1;j<=i;j++) {printf ("%d\t%d\t\t%d\t\t%d\t\t%d\t%f\n ", J,starT,RUNNING[J],START+RUNNING[J],START+RUNNING[J]-REACH[J], (float) (start+running[j]-reach[j])/running[j]); start= Start+running[j];if (start<reach[j+1])//arrival time vs. run time start=reach[j+1];}} if (n==2) {//sjfprintf ("sjf\n");p rintf ("The job number start time \ t run time \ t completes the time \ t turnaround time with right turnaround time \ n"); Start=reach[1];for (j=1;j<=i ; j + +) {printf ("%d\t%d\t\t%d\t\t%d\t\t%d\t%f\n", J,start,running[j],start+running[j],start+running[j]-reach[j], ( float) (Start+running[j]-reach[j])/running[j]); for (k=j;k<=i;k++) {if (start+running[j]>reach[k+1]) max=k;} for (l=j;l<max;l++) {for (m=0;m<max-l;m++) {if (running[m]>running[m+1]) {temp=running[m];running[m]= RUNNING[M+1]; RUNNING[M+1]=TEMP;TEMP=REACH[M];REACH[M]=REACH[M+1];   Reach[m+1]=temp;} }}start=start+running[j];if (start<reach[j+1])//arrival time vs. run time start=reach[j+1];} }if (n==3) {printf ("hrrf\n"), Start=reach[1];p rintf ("job number start time \ t run time \ t finish time \ T" turnaround time with right turnaround time \ n "); for (j=1;j<=i;j++) { printf ("%d\t%d\t\t%d\t\t%d\t\t%d\t%f\n", J,start,running[j],start+running[j],start+runniNG[J]-REACH[J], (float) (start+running[j]-reach[j])/running[j]); Start=start+running[j];for (k=j;k<=i;k++) {if (start+running[j]>reach[k+1]) max=k;} for (k=2;k<=max;k++) {if (Start!=reach[k]) {respond[k]=1+running[k]/(start-reach[k]);//Response ratio}}for (l=j;l<max;l+ +) {for (m=0;m<max-l;m++) {if (respond[m]>respond[m+1]) {temp=running[m];running[m]=running[m+1]; running[m+1] =TEMP;TEMP=REACH[M];REACH[M]=REACH[M+1]; REACH[M+1]=TEMP;TEMP=RESPOND[M];RESPOND[M]=RESPOND[M+1];   Respond[m+1]=temp;}   }}}}}

Experiment two scheduling

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.