Rotation scheduling algorithm

Source: Internet
Author: User

#include <stdio.h>

#include <stdlib.h>

#define N 100

typedef struct PROCESS {

int num;

int time;

int start;

int end;

int begin;

int freetime;

int arrivetime;

int finish;

int turn;

Double reaction;

Double average;

}

P

P a[n],b;

int wordtime=0;

int decide (n)

{

int i,t=0;

for (i=0;i<n;i++)

{

if (a[i].end==1)

{

T=1;

}

Else

{

R=v;

Break

}

}

if (t==0) return 0;

else return 1;

}

void rr (int i,int j,int n,int x)

{while (decide (n) ==0)

{

J=1;

for (i=0;i<n;i++) {

if (a[i].end==1) {

}

Else

if (a[i].end==0) {

if (a[i].arrivetime<=wordtime)

{

if (a[i].freetime>0)

{

a[i].freetime--;

wordtime++;

}

if (a[i].freetime==0)

{

a[i].end=1;

A[i].finish=wordtime;

}

}

else {

for (j=i;j<n;j++) {

if (a[j].arrivetime<=wordtime&&a[j].end==0)

{

x=0;

I=j-1;

Break

}

else if (j==i-1)

{

X=1;

Break

}

Else

X=1;

if (j==n-1&&i!=0)

J=-1;

} if (x==1)

wordtime++;

}

}

}

}

}

void Main () {

int n=5,i,t,sum=0,num=2,j,x=1;

Double average=0,turn=0;

printf ("Please enter the number of processes:");

scanf ("%d", &n);

for (i=0;i<n;i++) {

printf ("\ n");

printf ("Please enter the arrival time of%d processes:", i+1);

scanf ("%d", &a[i].arrivetime);

printf ("Please enter the first%d process takes time:", i+1);

scanf ("%d", &a[i].time);

printf ("\ n");

A[i].start=a[i].arrivetime;

A[i].freetime=a[i].time;

Time remaining assignment

a[i].num=i+1;

A[i].start=a[i].end=0;

}//input data

for (i=0;i<n;i++) {

for (t=i+1;t<n;t++) {

if (a[t].arrivetime<a[i].arrivetime) {

B=a[i];

A[I]=A[T];

A[t]=b;

}

else if (a[t].arrivetime==a[i].arrivetime)

{

if (a[i].time>a[t].time)

{

B=a[i];

A[I]=A[T];

A[t]=b;

}

}

}

}//sort

RR (I,J,N,X);

for (i=0;i<n;i++)

{

A[i].turn=a[i].finish-a[i].arrivetime;

A[i].average= (float) a[i].turn/a[i].time;

}

printf ("Process number \ t" time \ T "turnaround time \ T");

for (i=0;i<n;i++)

printf ("%d\t%d\t\t%d\t\t%.2f\n", a[i].num,a[i].finish,a[i].turn,a[i].average);

for (i=0;i<n;i++) {

turn=turn+ (float) A[i].turn;

average=average+ (float) a[i].turn/a[i].time;

}

turn=turn/n;

average=average/n;

printf ("Average turnaround time \ t average with right turnaround time \ n");

printf ("%.2f\t\t%.2f\n", turn,average);

Rotation scheduling algorithm

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.