Advertisement
Dark_Shard

SRTF (wip)

Aug 8th, 2019
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include<cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.     int processes = 0;
  11.     int temp = 0;
  12.  
  13.     cout << "Input processes" << endl;
  14.     cin >> processes;
  15.     system("color 0A");
  16.  
  17.     int procTime[processes][9] = {{0}};
  18.  
  19.     system("cls");
  20.     cout << "Shortest Remaining Time First " << endl;
  21.     cout << "=============================" << endl;
  22.  
  23.     cout << endl;
  24.     cout << "-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-" << endl;
  25.     cout << "Arrival Time" << endl;
  26.     cout << "-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-" << endl;
  27.     cout << "Input arrival time for : " << endl;
  28.     for(int a = 0; a < processes ; a++)
  29.     {
  30.         procTime[a][0] = a+1;
  31.         cout << "[P" << a+1 << "] : ";
  32.         cin >> procTime[a][1];
  33.     }
  34.  
  35.     cout << endl;
  36.     cout << "-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-" << endl;
  37.     cout << "Burst Time" << endl;
  38.     cout << "-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-" << endl;
  39.     cout << "Input Burst time for : " << endl;
  40.     for(int b= 0; b < processes ; b++)
  41.     {
  42.         cout << "[P" << b+1 << "] : ";
  43.         cin >> procTime[b][2];
  44.     }
  45.  
  46.     for(int sort = 0 ;sort < processes - 1 ; sort++)  // purpose of sorting only to get the first process to proceed
  47.     {
  48.         for(int sortInd = 0 ; sortInd < processes - sort - 1 ; sortInd ++)
  49.         {
  50.             if(procTime[sortInd][1] > procTime[sortInd+1][1])
  51.             {
  52.                 temp = procTime[sortInd][0];
  53.                 procTime[sortInd][0] = procTime[sortInd+1][0];
  54.                 procTime[sortInd+1][0] = temp;
  55.  
  56.                 temp = procTime[sortInd][1];
  57.                 procTime[sortInd][1] = procTime[sortInd+1][1];
  58.                 procTime[sortInd+1][1] = temp;
  59.  
  60.                 temp = procTime[sortInd][2];
  61.                 procTime[sortInd][2] = procTime[sortInd+1][2];
  62.                 procTime[sortInd+1][2] = temp;
  63.             }
  64.         }
  65.     }
  66.  
  67.     for(int a = 0; a < 78 ; a++)
  68.     {
  69.         cout << "-";
  70.     }
  71.     for(int gantt = 0; gantt < processes ; gantt++)
  72.     {
  73.         cout << procTime[gantt][0] << "   ";
  74.         if(procTime[gantt][2]> procTime[gantt+1][1])
  75.         {
  76.                 for(int x = 0)
  77.         }
  78.     }
  79.  
  80.  
  81.  
  82.  
  83.     /* Indexes~
  84.     *
  85.     *   0 - PID
  86.     *   1 - Arv Time
  87.     *   2 - Burst "
  88.     *   3 - Waiting "
  89.     *   4 - Turnaround "
  90.     *   5 - Start "
  91.     *   6 - End "
  92.     *   7 - Idle "
  93.     *   8 - Temp Burst Time Counter
  94.     */
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement