First Come First Serve (FCFS) / First In First Out (FIFO) Scheduling Algorithm -- Implementation in C++

  1 #include<iostream>
  2 #include<stdlib.h>
  3 
  4 using namespace std;
  5 struct node{
  6     int processId;
  7     int burstTime;
  8     int waitingTime;
  9     int turnAroundTime;
 10     struct node * next;
 11 };
 12 
 13 int main(){
 14     int i;
 15     int numberOfProcesses;
 16     struct node * process;
 17     struct node * temp;
 18     struct node * t;
 19     struct node * head = NULL;
 20 
 21     //number of processes
 22     cout << "\nNUMBER OF PROCESSES: ";
 23     cin >> numberOfProcesses;
 24 
 25     //burst time
 26     //create the linked list
 27     for(i=0; i<numberOfProcesses; i++){
 28         process = (struct node * ) malloc(sizeof(struct node));
 29         cout << "******************************\n";
 30         cout << "PROCESS " << i+1 << "\n";
 31         process->processId = i+1;
 32         cout << "\tBURST TIME: ";
 33         cin >> process->burstTime;
 34 
 35         if(head == NULL){
 36             head = process;
 37             head->next = NULL;
 38             head->waitingTime = 0;
 39             head->turnAroundTime = head->burstTime;
 40         } else {
 41             temp = head;
 42             while(temp != NULL){
 43                 t = temp;
 44                 temp = temp->next;
 45             }
 46             t->next = process;
 47             temp = process;
 48             temp->waitingTime = t->turnAroundTime;
 49             temp->turnAroundTime = t->turnAroundTime + temp->burstTime;
 50             temp->next = NULL;
 51         }
 52     }
 53 
 54     temp = head;
 55     //display
 56     cout << "\n========================================================\n";
 57     cout << "     PROCESS\t    BURST TIME\t   ";
 58     cout << "WAITING TIME\t   TURNAROUND TIME\n\n";
 59 
 60     while(temp != NULL)    {
 61         cout<<"\n\t"<<temp->processId;
 62         cout<<"\t\t"<<temp->burstTime;
 63         cout<<"\t\t"<<temp->waitingTime;
 64         cout<<"\t\t"<<temp->turnAroundTime;
 65         temp=temp->next;
 66     }
 67     cout<< "\n\n";
 68     return 0;
 69 } 

OUTPUT:

FCFS / FIFO

it is good resours

which compiler did u use for this?

GCC

im using GCC

i nid an output that looks like gantt chart

pls.. urgent

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.