scheduling process
I already have the coding in C
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
struct Queue // circular queue struct
{
int size;
int front;
int rear;
int *time_arr;
};
int isEmpty(struct Queue *q) // function to check is queue is empty
{
if (q->rear == q->front)
{
return 1;
}
return 0;
}
void enqueue(struct Queue *q, int time) // funntion to enqueue elements into the queue
{
q->rear = (q->rear + 1) % q->size;
q->time_arr[q->rear] = time;
}
int dequeue(struct Queue *q) // funciton to dequeue elements from queue
{
int a = -1;
q->front = (q->front + 1) % q->size;
a = q->time_arr[q->front];
}
int main()
{
// creating queue instances for gold and platinum customers
struct Queue gold_customer;
struct Queue platinum_customer;
// fixing size of queue as 10 , although user can change as per requirement
gold_customer.size = 10;
platinum_customer.size = 10;
// setting front and rear position of queue
gold_customer.front = gold_customer.rear = 0;
platinum_customer.rear = 0;
platinum_customer.front = 0;
// dynamically allocating the queue array space
gold_customer.time_arr = (int *)malloc(gold_customer.size * sizeof(int));
platinum_customer.time_arr = (int *)malloc(platinum_customer.size * sizeof(int));
printf("Enter total number of customers : \n");
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
printf("Select the type of customer you are : \n1.Gold 2.Platinum\n\n");
int x;
scanf("%d", &x);
int random;
if (x == 1)
{
random = rand() % 30;
enqueue(&gold_customer, random);
printf("Your expected waiting time is %dS. Thankyou for your patience. \n\n", random);
}
if (x == 2)
{
random = rand() % 30;
enqueue(&platinum_customer, random);
printf("Your expected waiting time is %dS. Thankyou for your patience. \n\n", random);
}
}
printf("\n\n");
while (isEmpty(&platinum_customer) == 0)
{
printf("Platinum customer with time expected %ds is served. \n", dequeue(&platinum_customer));
}
while (isEmpty(&gold_customer) == 0)
{
printf("Gold customer with time expected %ds is served. \n", dequeue(&gold_customer));
}
return 0;
}
Step by step
Solved in 2 steps with 1 images