#include #include #include /* My teacher did not supply me the inputs, so I generated the service times randomly */ int *genjobs ( int n ) { int *t, i; t = (int *)malloc(n * sizeof(int)); for (i=0; i ms) ms = rt; } return ms; } /* Returns the total waiting time of customers scheduled to counter k */ int waittime ( int *t, int *s, int k ) { int i, rt = 0, wt = 0; for (i=0; i= t[idx[j]]) { idxcpy[k] = idx[i]; ++i; } else { idxcpy[k] = idx[j]; ++j; } ++k; } while (i <= R1) { idxcpy[k] = idx[i]; ++i; ++k; } while (j <= R2) { idxcpy[k] = idx[j]; ++j; ++k; } for (i=0; i<=R-L; ++i) idx[L+i] = idxcpy[i]; free(idxcpy); } /* This is same as schedule1() with the exception that we look into t[] via the index array idx[]. */ int **schedule2 ( int *t, int n, int p ) { int **S, *freeat, *idx, i, j, min, minidx; idx = (int *)malloc(n * sizeof(int)); for (i=0; i= 3) { n = atoi(argv[1]); p = atoi(argv[2]); } else { printf("Enter n and p: "); scanf("%d%d", &n, &p); } printf("\nn = %d\np = %d\n\nEnter customer times:\n\n", n, p); t = genjobs(n); printf("\n+++ Schedule 1\n"); S1 = schedule1(t,n,p); printschedule(S1,p,t); printf("+++ Bank finishes at time %d\n", makespan(t,S1,p)); printf("+++ Total waiting time = %d\n", totalwaittime(t,S1,p)); printf("\n+++ Schedule 2\n"); S2 = schedule2(t,n,p); printschedule(S2,p,t); printf("+++ Bank finishes at time %d\n", makespan(t,S2,p)); printf("+++ Total waiting time = %d\n", totalwaittime(t,S2,p)); printf("\n+++ Schedule 3\n"); schedule3(S2,p); printschedule(S2,p,t); printf("+++ Bank finishes at time %d\n", makespan(t,S2,p)); printf("+++ Total waiting time = %d\n\n", totalwaittime(t,S2,p)); freeall(S1,S2,p,t); exit(0); }