Facebook
From Wet Camel, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 127
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4.  
  5. void fcfs(vector<int> arrival,vector<int> burst,bool flag)
  6. {
  7.     int start_time[105];
  8.     int finish_time[105];
  9.     int arri[105];
  10.     int burst_time[105];
  11.  
  12.     int turn_time[105];
  13.     int wait_time[105];
  14.  
  15.     int response_time[105];
  16.  
  17.  
  18.  
  19.  
  20.     int n=arrival.size();
  21.  
  22.  
  23.     vector <pair< int,pair<int,int> > > v;
  24.  
  25.  
  26.     for(int i=1;i<=n;i++)
  27.     {
  28.  
  29.         arri[i]=arrival[i-1];
  30.  
  31.         burst_time[i]=burst[i-1];
  32.  
  33.         v.push_back({arri[i],{i,burst_time[i]}});
  34.     }
  35.  
  36.     sort(v.begin(),v.end());
  37.  
  38.  
  39.  
  40.     start_time[0]=v[0].first;
  41.     finish_time[0]=v[0].first+v[0].second.second;
  42.  
  43.     int tot=0,idle=0;
  44.  
  45.     if(v[0].first>tot)
  46.     {
  47.         idle+=(v[0].first-tot);
  48.         tot=v[0].first;
  49.     }
  50.  
  51.     tot+=v[0].second.second;
  52.  
  53.  
  54.     for(int i=1;i<n;i++)
  55.     {
  56.         int id=v[i].second.first;
  57.         int arrival=v[i].first;
  58.  
  59.         if(arrival>tot)
  60.         {
  61.             idle+=(arrival-tot);
  62.             tot=arrival;
  63.  
  64.         }
  65.  
  66.         int ex=v[i].second.second;
  67.  
  68.         finish_time[i]=max(finish_time[i-1],v[i].first)+ex;
  69.         start_time[i]=max(finish_time[i-1],v[i].first);
  70.  
  71.         tot+=ex;
  72.     }
  73.  
  74.  
  75.  
  76.  
  77.     double tot_wait_time=0,tot_turn_time=0;
  78.  
  79.     for(int i=0;i<n;i++)
  80.     {
  81.         turn_time[i]=finish_time[i]-v[i].first;
  82.         tot_turn_time+=finish_time[i]-v[i].first;
  83.     }
  84.  
  85.     for(int i=0;i<n;i++)
  86.     {
  87.         wait_time[i]=turn_time[i]-v[i].second.second;
  88.         tot_wait_time+=turn_time[i]-v[i].second.second;
  89.     }
  90.  
  91.     for(int i=0;i<n;i++) response_time[i]=wait_time[i];
  92.  
  93.     if(flag)
  94.     {
  95.  
  96.  
  97.     cout<<"Gannt chart "<<endl;
  98.  
  99.  
  100.  
  101.     vector< pair<int,int> > ans;
  102.     for(int i=0;i<n;i++)
  103.     {
  104.         ans.push_back({start_time[i],finish_time[i]});
  105.     }
  106.  
  107.     int prev=0,idx=0;
  108.     for(auto it:ans)
  109.     {
  110.         if(start_time[idx]!=prev)
  111.         {
  112.             cout<<prev<<" IDLE "<<start_time[idx];
  113.             cout<<" P"<<v[idx].second.first<<" ";
  114.         }
  115.         else cout<<prev<<" P"<<v[idx].second.first<<" ";
  116.  
  117.         prev=finish_time[idx];
  118.         idx++;
  119.     }
  120.     cout<<finish_time[idx-1]<<endl;
  121.  
  122.  
  123.  
  124.     for(int i=0;i<n;i++)
  125.     {
  126.  
  127.  
  128.         cout<<"Process: P"<<v[i].second.first<<" Finish time:  "<<finish_time[i]<<" ";
  129.         cout<<"Response time:  "<<response_time[i]<<" ";
  130.         cout<<"Waiting time:  "<<wait_time[i]<<" ";
  131.         cout<<"Turnaround time:  "<<turn_time[i]<<" ";
  132.         cout<<endl;
  133.  
  134.     }
  135.  
  136.     cout<<endl;
  137.  
  138.     }
  139.  
  140.     double s1=(double)tot_wait_time/n;
  141.  
  142.     double s2=(double)tot_turn_time/n;
  143.  
  144.  
  145.     if(flag)
  146.     {
  147.         cout<<"Average waiting time :"<<s1<<endl;
  148.         cout<<"Average turn arround time :"<<s2<<endl;
  149.         cout<<"Total Idle time : "<<idle<<endl;
  150.     }
  151.     else
  152.     {
  153.        cout << "Algorithm: "<<1<<'\t'<<"Average Waiting Time: "<<s1;
  154.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  155.     }
  156.  
  157. }
  158.  
  159.  
  160.  
  161. void non_preemptive_sjf(vector<int>arrival,vector<int>burst,bool flag)
  162. {
  163.     long long int n=arrival.size();
  164.  
  165.  
  166.     vector<pair<pair<long long int,long long int>, long long int> > v;
  167.     long long int endTime[105];
  168.     long long int response_time[105];
  169.  
  170.     for (long long int i = 0; i < n; i++)
  171.     {
  172.  
  173.         long long int ar=arrival[i];
  174.  
  175.         long long int bt=burst[i];
  176.  
  177.         v.push_back({{ar, bt}, i+1});
  178.     }
  179.     sort(v.begin(), v.end());
  180.     set<long long int> s;
  181.     long long int start_time[105];
  182.     start_time[0]=v[0].first.first;
  183.  
  184.     long long int idle=0;
  185.  
  186.     for (long long int i = 0; i < n; i++)
  187.     {
  188.         if (i == 0)
  189.         {
  190.             endTime[i] = v[i].first.first + v[i].first.second;
  191.             s.insert(v[i].second);
  192.         }
  193.         else
  194.         {
  195.             long long int mn = LLONG_MAX;
  196.             long long int id = -1;
  197.  
  198.             for (long long int j = 0; j < n; j++)
  199.             {
  200.                 if (v[j].first.first <= endTime[i - 1] && s.count(v[j].second) == 0 && v[j].first.second < mn)
  201.                 {
  202.                     id = j;
  203.                     mn = v[j].first.second;
  204.                 }
  205.             }
  206.             if (id != -1)
  207.             {
  208.                 swap(v[id], v[i]);
  209.                 s.insert(v[i].second);
  210.                 endTime[i] = endTime[i - 1] + v[i].first.second;
  211.  
  212.                 sort(v.begin()+ i+1, v.end());
  213.             }
  214.             else
  215.             {
  216.                 endTime[i] = v[i].first.first + v[i].first.second;
  217.                 s.insert(v[i].second);
  218.             }
  219.             start_time[i]=max(endTime[i-1],v[i].first.first);
  220.         }
  221.     }
  222.  
  223.  
  224.     long long int turnAround[105];
  225.     long long int waitingTime[105];
  226.     double tot_turn_time = 0;
  227.     double tot_wait_time = 0;
  228.  
  229.     for (long long int i = 0; i < n; i++)
  230.     {
  231.         turnAround[i] = endTime[i] - v[i].first.first;
  232.         waitingTime[i] = turnAround[i] - v[i].first.second;
  233.         tot_turn_time += turnAround[i];
  234.         tot_wait_time += waitingTime[i];
  235.     }
  236.  
  237.  
  238.     for(int i=0;i<n;i++) response_time[i]=waitingTime[i];
  239.  
  240.     double s1=(double)tot_wait_time/n;
  241.  
  242.     double s2=(double)tot_turn_time/n;
  243.  
  244.     if(flag)
  245.     {
  246.  
  247.     cout<<"Gantt Chart:"<<endl;
  248.  
  249.     vector<pair<long long int,long long int> > ans;
  250.     for(long long int i=0;i<n;i++)
  251.     {
  252.         ans.push_back({start_time[i],endTime[i]});
  253.     }
  254.  
  255.     long long int prev=0,idx=0;
  256.     for(auto it:ans)
  257.     {
  258.         if(start_time[idx]!=prev)
  259.         {
  260.             cout<<prev<<" IDLE "<<start_time[idx];
  261.             cout<<" P"<<v[idx].second<<" ";
  262.             idle+=(start_time[idx]-prev);
  263.  
  264.         }
  265.         else cout<<prev<<" P"<<v[idx].second<<" ";
  266.  
  267.         prev=endTime[idx];
  268.         idx++;
  269.     }
  270.     cout<<endTime[idx-1]<<endl;
  271.  
  272.     for(int i=0;i<n;i++)
  273.     {
  274.  
  275.         cout<<"Process: P"<<v[i].second<<" Finish time:  "<<endTime[i]<<" ";
  276.         cout<<"Response time:  "<<response_time[i]<<" ";
  277.         cout<<"Waiting time:  "<<waitingTime[i]<<" ";
  278.         cout<<"Turnaround time:  "<<turnAround[i]<<" ";
  279.         cout<<endl;
  280.  
  281.     }
  282.  
  283.     cout<<endl;
  284.  
  285.     }
  286.  
  287.     if(flag)
  288.     {
  289.         cout<<"Average waiting time :"<<s1<<endl;
  290.         cout<<"Average turn arround time :"<<s2<<endl;
  291.         cout<<"Total Idle time : "<<idle<<endl;
  292.     }
  293.     else
  294.     {
  295.        cout << "Algorithm: "<<2<<'\t'<<"Average Waiting Time: "<<s1;
  296.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  297.     }
  298. }
  299.  
  300.  
  301.  
  302. ///map<int,int>mp;
  303. typedef pair<int,pair<int,int>>pi;
  304. ///vector<pair<int,pair<int,int>>>v;
  305.  
  306. void preemptive_sjf(vector<int>arrival,vector<int>burst,bool f)
  307. {
  308.    vector<pair<int,pair<int,int>>>v;
  309.    map<int,int>mp;
  310.  
  311.     int n=arrival.size();
  312.  
  313.  
  314.  
  315.     int finish_t[100];
  316.     int flag[100];
  317.     int resp_t[100];
  318.     int burst_time[102];
  319.     int  arri_time[102];
  320.      vector<pair<int,int>>gantchart;
  321.      memset(flag,0,sizeof(flag));
  322.      memset(resp_t,0,sizeof(resp_t));
  323.      priority_queue<pi,vector<pi>,greater<pi>>q;
  324.  
  325.  
  326.      for(int i=1;i<=n;i++)
  327.      {
  328.  
  329.         arri_time[i]=arrival[i-1];
  330.  
  331.         burst_time[i]=burst[i-1];
  332.         v.push_back({arri_time[i],{burst_time[i],i}});
  333.  
  334.         ///flag[i-1]=0;
  335.  
  336.     }
  337.  
  338.     sort(v.begin(),v.end());
  339.  
  340.     q.push({v[0].second.first,{v[0].first,v[0].second.second}});
  341.     int cur=0;
  342.     cur=v[0].first;
  343.  
  344.     flag[0]=1;
  345.     int total_idle=cur;
  346.     if(cur!=0){
  347.         mp[0]=cur;
  348.     }
  349.     int cnt=1;
  350.     while(!q.empty())
  351.         {
  352.         int y=q.top().second.second;
  353.         int x=q.top().first;
  354.         int ar=q.top().second.first;
  355.         q.pop();
  356.  
  357.         if(x>=1){
  358.             if(!resp_t[y]){
  359.                 resp_t[y]=cur;
  360.             }
  361.             if(cnt<n)
  362.             {
  363.             cur++;
  364.             finish_t[y]=cur;
  365.             x--;
  366.             gantchart.push_back({y,cur});
  367.             }
  368.             else{
  369.             finish_t[y]=cur+x;
  370.             cur+=x;
  371.             x=0;
  372.             gantchart.push_back({y,cur});
  373.             }
  374.         }
  375.         for(int i=0;i<n;i++){
  376.  
  377.             if(v[i].first<=cur && flag[i]==0){
  378.                   q.push({v[i].second.first,{v[i].first,v[i].second.second}});
  379.                  cnt++;
  380.                  flag[i]=1;
  381.             }
  382.         }
  383.         if(x>0){
  384.            q.push({x,{ar,y}});
  385.         }
  386.         if(q.empty() and cnt<n )
  387.         {
  388.             for(int i=0;i<n;i++){
  389.                 if(flag[i]==0){
  390.                     q.push({v[i].second.first,{v[i].first,v[i].second.second}});
  391.                    total_idle+= v[i].first-cur;
  392.                    mp[cur]=v[i].first;
  393.                    cur=v[i].first;
  394.                    flag[i]=1;
  395.                    cnt++;
  396.                    break;
  397.                 }
  398.             }
  399.         }
  400.     }
  401.  
  402.     if(f)
  403.     {
  404.  
  405.     cout<<"Gantt Chart: :";
  406.     cout<<0<<" ";
  407.     if(mp[0]!=0)cout<<"Idle "<<mp[0]<<" ";
  408.     for(auto u:gantchart)
  409.     {
  410.         cout<<"P"<<u.first<<" "<<u.second<<" ";
  411.         if(mp[u.second]!=0){
  412.             cout<<"Idle "<<mp[u.second]<<" ";
  413.  
  414.         }
  415.  
  416.     }
  417.     cout<<endl;
  418.     }
  419.  
  420.     int turnAround[101];
  421.     int waitingTime[101];
  422.     double avgTurnAround = 0;
  423.     double avgwaitingTime = 0;
  424.     for (int i = 1; i <= n; i++)
  425.     {
  426.         resp_t[i]=resp_t[i]-arri_time[i];
  427.         turnAround[i] = finish_t[i] - arri_time[i];
  428.         waitingTime[i] = turnAround[i] - burst_time[i];
  429.         ///cout<<"Turn "<<turnAround[i]<<" WAIT "<<waitingTime[i]<<endl;
  430.         avgTurnAround += turnAround[i];
  431.         avgwaitingTime += waitingTime[i];
  432.     }
  433.  
  434.     double s2=(double)avgTurnAround / n ;
  435.     double s1=(double)avgwaitingTime / n ;
  436.  
  437.     if(f)
  438.     {
  439.  
  440.     for (int i = 1; i <=n; i++)
  441.     {
  442.         cout<<"Process: p"<<i<<" Finish Time: "<<finish_t[i]<<" Response Time: "<<resp_t[i]<<" Waiting Time: "<<waitingTime[i] ;
  443.         cout<<" Turnaround Time: "<<turnAround[i]<<endl;
  444.     }
  445.  
  446.     cout << "Average waiting time: " <<s1<< endl;
  447.      cout << "Average turnaround time: " <<s2<< endl;
  448.  
  449.     cout<<"Total_Idle :"<<total_idle<<endl;
  450.  
  451.     }
  452.     else
  453.     {
  454.         cout << "Algorithm: "<<3<<'\t'<<"Average Waiting Time: "<<s1;
  455.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  456.     }
  457. }
  458.  
  459.  
  460.  
  461. struct job
  462. {
  463.     int PID, ART, BT, WT = 0, TAT =0, STT =-2, ENT = -2, RT, PRT, RSP;
  464.     bool f=0;
  465. };
  466. void sort_PID(int n, struct job (& b)[100])
  467. {
  468.     int i, j, t;
  469.     for(i=0; i<n-1; i++)
  470.     {
  471.         t=i;
  472.         for(j=i+1; j<n; j++)
  473.         {
  474.             if(b[j].PID<b[t].PID)
  475.                 t=j;
  476.         }
  477.         swap(b[i], b[t]);
  478.     }
  479. }
  480.  
  481. void sort_ART(int n, struct job (& b)[100])
  482. {
  483.     int i, j, t;
  484.     for(i=0; i<n-1; i++)
  485.     {
  486.         t=i;
  487.         for(j=i+1; j<n; j++)
  488.         {
  489.             if(b[j].ART < b[t].ART)
  490.                 t=j;
  491.         }
  492.         swap(b[i], b[t]);
  493.     }
  494. }
  495.  
  496.  
  497. int preemp_next_job(int CT,int n, struct job (& b)[100])
  498. {
  499.     if(b[0].ART>CT)
  500.     return -1;
  501.     int i=0;
  502.     int tmp = -1;
  503.     while(b[i].ART<=CT)
  504.     {
  505.         if(b[i].RT != 0 && tmp == -1)
  506.         {
  507.             tmp = i;
  508.         }
  509.  
  510.         else if(b[i].PRT < b[tmp].PRT && b[i].RT!=0) //Higher number higher priority(>)//Higher number lower priority (<)
  511.             tmp = i;
  512.         i++;
  513.         if(i>n)
  514.             break;
  515.     }
  516.         return tmp;
  517. }
  518.  
  519. int nonpreemp_next_job(int CT,int n, struct job (& a)[100])
  520. {
  521.     if(a[0].ART>CT)
  522.     return -1;
  523.     int i=0;
  524.     int tmp = -1;
  525.     while(a[i].ART<=CT)
  526.     {
  527.         if(a[i].RT != 0 && tmp == -1)
  528.         {
  529.             tmp = i;
  530.         }
  531.         else if(a[i].PRT < a[tmp].PRT && a[i].RT!=0) //Higher number higher priority(>)//Higher number lower priority (<)
  532.             tmp = i;
  533.         i++;
  534.         if(i>n)
  535.             break;
  536.     }
  537.         return tmp;
  538.  
  539. }
  540. void non_preemptive_priority(vector<int> arrival,vector<int> burst,vector<int> priority,bool flag)
  541. {
  542.     job a[100];
  543.     vector <int> GT;
  544.     int n=arrival.size(), i, j, T=0;
  545.  
  546.  
  547.     for(i=0; i<n; i++)
  548.     {
  549.              a[i].PID=i+1;
  550.  
  551.              a[i].ART=arrival[i];
  552.  
  553.              a[i].BT=burst[i];
  554.              a[i].RT = a[i].BT;
  555.  
  556.               a[i].PRT=priority[i];
  557.  
  558.  
  559.     }
  560. //Sort according to Arrival time
  561.     sort_ART(n,a);
  562. //gantt chart creation
  563.  
  564.    int CT = 0, cnt = 0;
  565.     while(1)
  566.     {
  567.             i = nonpreemp_next_job(CT,n, a);
  568.             if(i!=-1)
  569.             {
  570.                 while(a[i].RT!=0)
  571.                 {
  572.                     GT.push_back(i);
  573.                     a[i].RT--;
  574.                     CT++;
  575.                 }
  576.                     cnt++;
  577.             }
  578.             else
  579.             {
  580.                 CT++;
  581.                 GT.push_back(-1);
  582.             }
  583.         if(cnt==n)
  584.             break;
  585.     }
  586.    // Start time and total idle time using Gantt chart
  587.    int TOTAT_IDLE=0;
  588.     for(i=0; i<GT.size(); i++)
  589.     {
  590.         if(GT[i]!=-1 && a[GT[i]].STT==-2)
  591.         {
  592.             a[GT[i]].STT = i;
  593.         }
  594.         if(GT[i]==-1)
  595.             TOTAT_IDLE++;
  596.     }
  597.     // END time calculation using Gantt chart
  598.     for(i=GT.size()-1; i>=0; i--)
  599.     {
  600.         if(GT[i]!=-1 && a[GT[i]].ENT==-2)
  601.             a[GT[i]].ENT = i+1;
  602.     }
  603.     // other values using gantt chart
  604.     for(i=0; i<n; i++)
  605.     {
  606.         a[i].TAT = a[i].ENT - a[i].ART;
  607.         a[i].WT = a[i].TAT - a[i].BT;
  608.         a[i].RSP = a[i].STT - a[i].ART;
  609.  
  610.     }
  611.  
  612.     //gantt chart print
  613.  
  614.     if(flag)
  615.     {
  616.  
  617.     cout << "Gantt Chart" << endl << endl;
  618.  
  619.     int prev = -2;
  620.     for(i=0; i<GT.size(); i++)
  621.     {
  622.         if(GT[i]!=prev)
  623.         {
  624.             if(GT[i]!=-1)
  625.             cout << i << "  p" << a[GT[i]].PID << "  ";
  626.             else
  627.             cout << i << "  idle " ;
  628.         }
  629.         prev=GT[i];
  630.     }
  631.     cout << i;
  632.  
  633.     }
  634.  
  635.     cout<<endl;
  636.  
  637.     //Output print
  638.     //Sort according to Process ID
  639.     sort_PID(n, a);
  640.  
  641.     int TOTAL_TAT=0, TOTAL_WT=0;
  642.     ///cout << "PID\tArrival Time\tStart Time\tEnd Time\tTurn Around Time\tWaiting time\tResponse Time"<<endl;
  643.     for(i=0; i<n; i++)
  644.     {
  645.         /*cout << a[i].PID <<"\t";
  646.         cout << a[i].ART <<"\t\t";
  647.         cout << a[i].STT <<"\t\t";
  648.         cout << a[i].ENT <<"\t\t";
  649.         cout << a[i].TAT <<"\t\t\t";
  650.         cout << a[i].WT  <<"\t\t";
  651.         cout << a[i].RSP <<"\n";*/
  652.  
  653.         TOTAL_TAT += a[i].TAT;
  654.         TOTAL_WT += a[i].WT;
  655.     }
  656.  
  657.     double s2=double(TOTAL_TAT)/n;
  658.     double s1=double(TOTAL_WT)/n;
  659.  
  660.  
  661.  
  662.  
  663.     if(flag)
  664.     {
  665.  
  666.     for (int i = 0; i <n; i++)
  667.     {
  668.         cout<<"Process: p"<<a[i].PID<<" Finish Time: "<<a[i].ENT<<" Response Time: "<<a[i].RSP<<" Waiting Time: "<<a[i].WT ;
  669.         cout<<" Turnaround Time: "<<a[i].TAT<<endl;
  670.     }
  671.  
  672.      cout << "Average waiting time: " <<s1<< endl;
  673.      cout << "Average turnaround time: " <<s2<< endl;
  674.  
  675.     cout<<"Total_Idle :"<<TOTAT_IDLE<<endl;
  676.  
  677.     }
  678.     else
  679.     {
  680.         cout << "Algorithm: "<<4<<'\t'<<"Average Waiting Time: "<<s1;
  681.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  682.     }
  683.  
  684.  
  685. }
  686.  
  687. void preemptive_priority(vector<int> arrival,vector<int> burst,vector<int> priority,bool flag)
  688. {
  689.     job b[100];
  690.  
  691.     vector <int> GT;
  692.     int n=arrival.size(), i, j, T=0;
  693.  
  694.  
  695.     for(i=0; i<n; i++)
  696.     {
  697.             b[i].PID=i+1;
  698.  
  699.             b[i].ART=arrival[i];
  700.  
  701.              b[i].BT=burst[i];
  702.              b[i].RT = b[i].BT;
  703.  
  704.             b[i].PRT=priority[i];
  705.  
  706.     }
  707.     sort_ART(n, b);
  708.  
  709. //gantt chart creation
  710.    int CT = 0, cnt = 0;
  711.     while(1)
  712.     {
  713.         i = preemp_next_job(CT,n, b);
  714.         if(i!=-1)
  715.         {
  716.             GT.push_back(i);
  717.             b[i].RT--;
  718.             if(b[i].RT == 0)
  719.                 cnt++;
  720.             CT++;
  721.         }
  722.         else
  723.         {
  724.             CT++;
  725.             GT.push_back(-1);
  726.         }
  727.         if(cnt==n)
  728.             break;
  729.     }
  730.    // Start time and total idle time using Gantt Chart
  731.    int TOTAT_IDLE=0;
  732.     for(i=0; i<GT.size(); i++)
  733.     {
  734.         if(GT[i]!=-1 && b[GT[i]].STT==-2)
  735.         {
  736.             b[GT[i]].STT = i;
  737.         }
  738.         if(GT[i]==-1)
  739.             TOTAT_IDLE++;
  740.     }
  741.     // END time using gantt chart
  742.     for(i=GT.size()-1; i>=0; i--)
  743.     {
  744.         if(GT[i]!=-1 && b[GT[i]].ENT==-2)
  745.             b[GT[i]].ENT = i+1;
  746.     }
  747.     // other values using gantt chart
  748.     for(i=0; i<n; i++)
  749.     {
  750.         b[i].TAT = b[i].ENT - b[i].ART;
  751.         b[i].WT = b[i].TAT - b[i].BT;
  752.         b[i].RSP = b[i].STT - b[i].ART;
  753.     }
  754.  
  755.     //gantt chart print
  756.  
  757.     if(flag)
  758.     {
  759.  
  760.  
  761.     cout << "Gantt Chart" << endl << endl;
  762.     int prev = -2;
  763.     for(i=0; i<GT.size(); i++)
  764.     {
  765.         if(GT[i]!=prev)
  766.         {
  767.             if(GT[i]!=-1)
  768.             cout << i << "  p" << b[GT[i]].PID << "  ";
  769.             else
  770.             cout << i << "  idle  " ;
  771.         }
  772.         prev=GT[i];
  773.     }
  774.     cout << i;
  775.  
  776.     }
  777.  
  778.     //Output print
  779.     sort_PID(n, b);
  780.  
  781.     int TOTAL_TAT=0, TOTAL_WT=0;
  782.    // cout << "PID\tArrival Time\tStart Time\tEnd Time\tTurn Around Time\tWaiting time\tResponse Time"<<endl;
  783.  
  784.     for(i=0; i<n; i++)
  785.     {
  786.         /*cout << b[i].PID <<"\t";
  787.         cout << b[i].ART <<"\t\t";
  788.         cout << b[i].STT <<"\t\t";
  789.         cout << b[i].ENT <<"\t\t";
  790.         cout << b[i].TAT <<"\t\t\t";
  791.         cout << b[i].WT  <<"\t\t";
  792.         cout << b[i].RSP <<"\n";*/
  793.  
  794.         TOTAL_TAT += b[i].TAT;
  795.         TOTAL_WT += b[i].WT;
  796.     }
  797.  
  798.     double s1=double(TOTAL_WT)/n;
  799.     double s2=double(TOTAL_TAT)/n;
  800.  
  801.     if(flag)
  802.     {
  803.  
  804.     for (int i = 0; i <n; i++)
  805.     {
  806.         cout<<"Process: p"<<b[i].PID<<" Finish Time: "<<b[i].ENT<<" Response Time: "<<b[i].RSP<<" Waiting Time: "<<b[i].WT ;
  807.         cout<<" Turnaround Time: "<<b[i].TAT<<endl;
  808.     }
  809.  
  810.      cout << "Average waiting time: " <<s1<< endl;
  811.      cout << "Average turnaround time: " <<s2<< endl;
  812.  
  813.     cout<<"Total_Idle :"<<TOTAT_IDLE<<endl;
  814.  
  815.     }
  816.     else
  817.     {
  818.         cout << "Algorithm: "<<5<<'\t'<<"Average Waiting Time: "<<s1;
  819.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  820.     }
  821.  
  822. }
  823.  
  824.  
  825.  
  826.  
  827.  
  828.  
  829.  
  830. void round_robin(vector<int>ar,vector<int>bt,int tq,bool f)
  831. {
  832.     int arrival[5000],burst[5000],end_time[5000],id[5000],flag[5000],res_time[5000];
  833.     int n=ar.size();
  834.  
  835.     double turn_time[5000],wait_time[5000];
  836.  
  837.  
  838.  
  839.      vector< pair<int,pair<int,int>> >v;
  840.  
  841.      int context=0;
  842.  
  843.  
  844.     for(int i=1;i<=n;i++)
  845.     {
  846.         int x,y;
  847.         x=ar[i-1];
  848.         arrival[i]=x;
  849.  
  850.  
  851.         y=bt[i-1];
  852.         burst[i]=y;
  853.  
  854.         res_time[i]=-1;
  855.  
  856.         flag[i-1]=0;
  857.  
  858.         v.push_back({x,{i,y}});
  859.  
  860.     }
  861.  
  862.     int TQ=tq;
  863.  
  864.  
  865.     sort(v.begin(),v.end());
  866.  
  867.  
  868.     map<int,int> gap;  ///saves { idle time start, idle itme end }
  869.     vector<pair<int,int> > g;  ///saves the { pid, end time }
  870.  
  871.     queue< pair<int,int> > q;
  872.  
  873.     q.push({v[0].second.first,v[0].second.second});   ///id burst time
  874.     flag[0]=1;
  875.  
  876.     int cur_time=0,tot_idle=0;
  877.  
  878.     cur_time=v[0].first;
  879.  
  880.     ///idle in the start
  881.  
  882.     if(cur_time!=0)
  883.     {
  884.         tot_idle+=cur_time;
  885.         gap[0]=cur_time;
  886.     }
  887.  
  888.     int completed=0;
  889.  
  890.     while(!q.empty() and completed!=n)
  891.     {
  892.  
  893.         int id=q.front().first;
  894.         int bur=q.front().second;
  895.         q.pop();
  896.  
  897.         ///cout<<"ID "<<id<<" BUR "<<bur<<endl;
  898.  
  899.         context++;
  900.  
  901.  
  902.  
  903.  
  904.         if(res_time[id]!=0) res_time[id]=cur_time;
  905.  
  906.  
  907.         int rem;
  908.         if(TQ>=bur)
  909.         {
  910.             cur_time+=bur;
  911.            /// burst2[pt]=0;
  912.            end_time[id]=cur_time;
  913.            rem=0;
  914.            completed++;
  915.  
  916.         }
  917.         else
  918.         {
  919.             cur_time+=TQ;
  920.            /// burst2[pt]-=TQ;
  921.            rem=bur-TQ;
  922.         }
  923.  
  924.         g.push_back({id,cur_time});
  925.  
  926.  
  927.         for(int i=0;i<n;i++)
  928.         {
  929.             if(v[i].first<=cur_time and flag[i]==0)
  930.             {
  931.                 q.push({v[i].second.first,v[i].second.second});
  932.  
  933.                 flag[i]=1;
  934.             }
  935.         }
  936.  
  937.         if(rem) q.push({id,rem});
  938.  
  939.         ///idle time in middle
  940.  
  941.         if(q.empty())
  942.         {
  943.             if(completed!=n)
  944.             {
  945.                 for(int i=0;i<n;i++)
  946.                 {
  947.                     if(flag[i]==0)
  948.                     {
  949.                         q.push({v[i].second.first,v[i].second.second});
  950.                         tot_idle+=(v[i].first-cur_time);
  951.  
  952.                         gap[cur_time]=v[i].first;
  953.  
  954.                         cur_time=v[i].first;
  955.                         flag[i]=1;
  956.  
  957.                         break;
  958.                     }
  959.                 }
  960.  
  961.             }
  962.  
  963.         }
  964.  
  965.  
  966.  
  967.     }
  968.  
  969.  
  970.     for(int i=1;i<=n;i++)
  971.     {
  972.         int x=res_time[i];
  973.         res_time[i]=x-arrival[i];
  974.     }
  975.  
  976.     double tot_turn_time=0;
  977.     double tot_wait_time=0;
  978.  
  979.     for(int i=1;i<=n;i++)
  980.     {
  981.         double x=end_time[i]-arrival[i];
  982.         turn_time[i]=x;
  983.         tot_turn_time+=x;
  984.     }
  985.  
  986.     for(int i=1;i<=n;i++)
  987.     {
  988.         double x=turn_time[i]-burst[i];
  989.         wait_time[i]=x;
  990.         tot_wait_time+=x;
  991.     }
  992.  
  993.  
  994.  
  995.     if(f)
  996.     {
  997.  
  998.     cout<<"Gantt Chart: :";
  999.     cout<<0<<" ";
  1000.  
  1001.     if(gap[0]!=0)cout<<"Idle "<<gap[0]<<" ";
  1002.  
  1003.     for(auto it:g)
  1004.     {
  1005.         int id=it.first;
  1006.         int ed=it.second;
  1007.  
  1008.         cout<<"P"<<id<<" "<<ed<<" ";
  1009.  
  1010.         if(gap[ed]!=0)
  1011.         {
  1012.             cout<<"Idle "<<gap[ed]<<" ";
  1013.         }
  1014.     }
  1015.     cout<<endl;
  1016.  
  1017.     }
  1018.  
  1019.     double s1=tot_wait_time/n;
  1020.     double s2=tot_turn_time/n;
  1021.  
  1022.     if(f)
  1023.     {
  1024.  
  1025.     for(int i=1;i<=n;i++)
  1026.     {
  1027.         cout<<"Process: p"<<i<<" Finish Time: "<<end_time[i]<<" Response Time: "<<res_time[i]<<" Waiting Time: "<<wait_time[i] ;
  1028.         cout<<" Turnaround Time: "<<turn_time[i]<<endl;
  1029.         cout<<endl;
  1030.     }
  1031.     cout<<endl;
  1032.  
  1033.  
  1034.  
  1035.     cout << "Average waiting time: " <<s1<< endl;
  1036.     cout << "Average turnaround time: " <<s2<< endl;
  1037.  
  1038.     cout<<"Total_Idle :"<<tot_idle<<endl;
  1039.  
  1040.     }
  1041.     else
  1042.     {
  1043.         cout << "Algorithm: "<<6<<'\t'<<"Average Waiting Time: "<<s1;
  1044.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  1045.     }
  1046.  
  1047.     context--;
  1048.  
  1049.     cout<<"CONTEXT SWITCH "<<context<<endl;
  1050.  
  1051. }
  1052.  
  1053.  
  1054.  
  1055. queue<int> readyq;
  1056.  
  1057. int finding_time_quantum()
  1058. {
  1059.  
  1060.     double sm=0,avg,sz=readyq.size();
  1061.  
  1062.     vector<int>rem_time;
  1063.  
  1064.  
  1065.     while(!readyq.empty())
  1066.     {
  1067.         int x=readyq.front();
  1068.         readyq.pop();
  1069.  
  1070.         rem_time.push_back(x);
  1071.  
  1072.         sm=(double)sm+x;
  1073.  
  1074.  
  1075.     }
  1076.  
  1077.  
  1078.     avg=sm/(sz);
  1079.  
  1080.     int t=ceil(avg);
  1081.  
  1082.     for(auto it:rem_time)
  1083.     {
  1084.        readyq.push(it);
  1085.  
  1086.     }
  1087.  
  1088.     return t;
  1089.  
  1090. }
  1091.  
  1092. void proposed_algo(vector<int>ar,vector<int>bt,vector<int>priority,bool f)
  1093. {
  1094.     while(!readyq.empty()) readyq.pop();
  1095.  
  1096.     int arrival[5000],burst[5000],end_time[5000],id[5000],flag[5000],res_time[5000],prio[5000];
  1097.     int n=ar.size();
  1098.  
  1099.     double turn_time[5000],wait_time[5000];
  1100.  
  1101.     vector< pair< int,pair <int,pair<int,int> > > >v;
  1102.     int completed=0;
  1103.     int context=0;
  1104.  
  1105.  
  1106.     for(int i=1;i<=n;i++)
  1107.     {
  1108.         int x,y,p;
  1109.  
  1110.         x=ar[i-1];
  1111.         arrival[i]=x;
  1112.  
  1113.  
  1114.         y=bt[i-1];
  1115.         burst[i]=y;
  1116.  
  1117.  
  1118.         p=priority[i-1];
  1119.         prio[i]=p;
  1120.  
  1121.         res_time[i]=-1;
  1122.  
  1123.         flag[i-1]=0;
  1124.  
  1125.  
  1126.  
  1127.         v.push_back({arrival[i],{prio[i],{burst[i],i}}});
  1128.  
  1129.     }
  1130.  
  1131.     int TQ;
  1132.  
  1133.  
  1134.     sort(v.begin(),v.end());
  1135.     ///for(auto it:v) cout<<it.first<<" ";
  1136.    /// cout<<endl;
  1137.  
  1138.  
  1139.     map<int,int> gap;  ///saves { idle time start, idle itme end }
  1140.  
  1141.     vector<pair<int,int> > g;  ///saves the { pid, end time }
  1142.  
  1143.     queue< pair<int,int> > q;
  1144.  
  1145.  
  1146.  
  1147.     q.push({v[0].second.second.second,v[0].second.second.first});   ///id burst time
  1148.     flag[0]=1;
  1149.  
  1150.  
  1151.  
  1152.     readyq.push(v[0].second.second.first);
  1153.  
  1154.  
  1155.  
  1156.     int cur_time=0,tot_idle=0;
  1157.  
  1158.     cur_time=v[0].first;
  1159.  
  1160.     ///idle in the start
  1161.  
  1162.     if(cur_time!=0)
  1163.     {
  1164.         tot_idle+=cur_time;
  1165.         gap[0]=cur_time;
  1166.     }
  1167.  
  1168.  
  1169.  
  1170.     while(!q.empty() and completed!=n)
  1171.     {
  1172.  
  1173.         int id=q.front().first;
  1174.         int bur=q.front().second;
  1175.         q.pop();
  1176.  
  1177.         context++;
  1178.  
  1179.  
  1180.  
  1181.         ///cout<<"ID "<<id<<" bur "<<bur<<endl;
  1182.  
  1183.  
  1184.  
  1185.         TQ=finding_time_quantum();
  1186.  
  1187.         ///cout<<"TQ "<<TQ<<endl;
  1188.  
  1189.         readyq.pop();
  1190.  
  1191.  
  1192.  
  1193.         if(res_time[id]==-1) res_time[id]=cur_time;
  1194.  
  1195.  
  1196.         int rem;
  1197.         if(TQ>=bur)
  1198.         {
  1199.            cur_time+=bur;
  1200.  
  1201.            end_time[id]=cur_time;
  1202.            rem=0;
  1203.            completed++;
  1204.  
  1205.  
  1206.  
  1207.         }
  1208.         else
  1209.         {
  1210.             cur_time+=TQ;
  1211.             rem=bur-TQ;
  1212.  
  1213.  
  1214.         }
  1215.  
  1216.         g.push_back({id,cur_time});
  1217.  
  1218.  
  1219.  
  1220.         vector< pair< int,pair <int,pair<int,int> > > >rv;  /// p, burst , arri ,id
  1221.  
  1222.  
  1223.         for(int i=0;i<n;i++)
  1224.         {
  1225.             if(v[i].first<=cur_time and flag[i]==0)
  1226.             {
  1227.                 ///cout<<""
  1228.  
  1229.                 ///q.push({v[i].second.second.second,v[i].second.second.first});
  1230.                 rv.push_back({v[i].second.first,{v[i].second.second.first,{v[i].first,v[i].second.second.second}}});
  1231.  
  1232.                 flag[i]=1;
  1233.  
  1234.                 ///readyq.push(v[i].second.second.first);
  1235.             }
  1236.         }
  1237.         sort(rv.begin(),rv.end());
  1238.  
  1239.         for(auto it:rv)
  1240.         {
  1241.             q.push({it.second.second.second,it.second.first});
  1242.             readyq.push(it.second.first);
  1243.         }
  1244.  
  1245.  
  1246.  
  1247.        /// cout<<"ID2 "<<id<<" bur "<<rem<<endl;
  1248.  
  1249.         if(rem!=0)
  1250.         {
  1251.             q.push({id,rem});
  1252.  
  1253.             readyq.push(rem);
  1254.  
  1255.         }
  1256.  
  1257.  
  1258.  
  1259.  
  1260.         ///idle time in middle
  1261.  
  1262.         if(q.empty())
  1263.         {
  1264.             if(completed!=n)
  1265.             {
  1266.                 for(int i=0;i<n;i++)
  1267.                 {
  1268.                     if(flag[i]==0)
  1269.                     {
  1270.                         ///cout<<"I "<<i<<endl;
  1271.  
  1272.                        q.push({v[i].second.second.second,v[i].second.second.first});
  1273.                         tot_idle+=(v[i].first-cur_time);
  1274.  
  1275.                         gap[cur_time]=v[i].first;
  1276.  
  1277.                         cur_time=v[i].first;
  1278.                         flag[i]=1;
  1279.  
  1280.                         readyq.push(v[i].second.second.first);
  1281.  
  1282.                         break;
  1283.                     }
  1284.                 }
  1285.  
  1286.             }
  1287.  
  1288.         }
  1289.  
  1290.  
  1291.  
  1292.  
  1293.  
  1294.  
  1295.  
  1296.     }
  1297.  
  1298.  
  1299.     for(int i=1;i<=n;i++)
  1300.     {
  1301.         int x=res_time[i];
  1302.         res_time[i]=x-arrival[i];
  1303.     }
  1304.  
  1305.     double tot_turn_time=0;
  1306.     double tot_wait_time=0;
  1307.  
  1308.     for(int i=1;i<=n;i++)
  1309.     {
  1310.         double x=end_time[i]-arrival[i];
  1311.         turn_time[i]=x;
  1312.         tot_turn_time+=x;
  1313.     }
  1314.  
  1315.     for(int i=1;i<=n;i++)
  1316.     {
  1317.         double x=turn_time[i]-burst[i];
  1318.         wait_time[i]=x;
  1319.         tot_wait_time+=x;
  1320.     }
  1321.  
  1322.  
  1323.  
  1324.     if(f)
  1325.     {
  1326.  
  1327.  
  1328.     cout<<"Gantt Chart: :";
  1329.     cout<<0<<" ";
  1330.  
  1331.     if(gap[0]!=0)cout<<"Idle "<<gap[0]<<" ";
  1332.  
  1333.     for(auto it:g)
  1334.     {
  1335.         int id=it.first;
  1336.         int ed=it.second;
  1337.  
  1338.         cout<<"P"<<id<<" "<<ed<<" ";
  1339.  
  1340.         if(gap[ed]!=0)
  1341.         {
  1342.             cout<<"Idle "<<gap[ed]<<" ";
  1343.         }
  1344.     }
  1345.     cout<<endl;
  1346.  
  1347.     }
  1348.  
  1349.     double s1=tot_wait_time/n;
  1350.     double s2=tot_turn_time/n;
  1351.  
  1352.     if(f)
  1353.     {
  1354.  
  1355.     for(int i=1;i<=n;i++)
  1356.     {
  1357.         cout<<"Process: p"<<i<<" Finish Time: "<<end_time[i]<<" Response Time: "<<res_time[i]<<" Waiting Time: "<<wait_time[i] ;
  1358.         cout<<" Turnaround Time: "<<turn_time[i]<<endl;
  1359.         cout<<endl;
  1360.     }
  1361.     cout<<endl;
  1362.  
  1363.  
  1364.  
  1365.     cout << "Average waiting time: " <<s1<< endl;
  1366.     cout << "Average turnaround time: " <<s2<< endl;
  1367.  
  1368.     cout<<"Total_Idle :"<<tot_idle<<endl;
  1369.  
  1370.     }
  1371.     else
  1372.     {
  1373.          ///cout << "Average waiting time: " <<s1<< endl;
  1374.        ///cout << "Average turnaround time: " <<s2<< endl;
  1375.         cout << "Algorithm: "<<7<<'\t'<<"Average Waiting Time: "<<s1;
  1376.        cout<<'\t'<<"Average Turnaround Time: "<<s2<< endl;
  1377.     }
  1378.  
  1379.  
  1380.     context--;
  1381.     cout<<"CONTEXT "<<context<<endl;
  1382.  
  1383.  
  1384.  
  1385. }
  1386.  
  1387.  
  1388. void compare_all(vector<int> arrival,vector<int> burst,vector<int> priority,int tq)
  1389. {
  1390.     fcfs(arrival,burst,0);
  1391.     non_preemptive_sjf(arrival,burst,0);
  1392.     preemptive_sjf(arrival,burst,0);
  1393.  
  1394.     non_preemptive_priority(arrival,burst,priority,0);
  1395.     preemptive_priority(arrival,burst,priority,0);
  1396.  
  1397.  
  1398.     round_robin(arrival,burst,tq,0);
  1399.     proposed_algo(arrival,burst,priority,0);
  1400. }
  1401.  
  1402.  
  1403. int main()
  1404. {
  1405.     while(1)
  1406.     {
  1407.  
  1408.  
  1409.         cout<<"1: FCFS"<<endl;
  1410.         cout<<"2: Non-Preemptive-SJF"<<endl;
  1411.         cout<<"3: Preemptive-SJF"<<endl;
  1412.         cout<<"4: Non-Preemptive-Priority"<<endl;
  1413.         cout<<"5: Preemptive-Priority"<<endl;
  1414.         cout<<"6: Round-Robin"<<endl;
  1415.         cout<<"7: Our-Proposed-Algorithm"<<endl;
  1416.         cout<<"8: Compare-All"<<endl;
  1417.         cout<<"9: Exit "<<endl;
  1418.  
  1419.  
  1420.         cout<<"Input your Choice: ";
  1421.  
  1422.         int choice;cin>>choice;
  1423.         if(choice==9) return 0;
  1424.  
  1425.  
  1426.         cout<<"Number of Process,n: ";
  1427.         int n;cin>>n;
  1428.  
  1429.         cout<<endl;
  1430.  
  1431.         int tq;
  1432.  
  1433.         vector<int> arrival,burst,priority;
  1434.  
  1435.         if(choice>=1 and choice<=3)
  1436.         {
  1437.  
  1438.         for(int i=1;i<=n;i++)
  1439.         {
  1440.             int a,b;
  1441.             cout<<"Enter the arrival time of P"<<i<< ": ";
  1442.             cin>>a;
  1443.             arrival.push_back(a);
  1444.  
  1445.             cout<<"Enter the burst time of P" <<i<< ": ";
  1446.             cin>>b;
  1447.             burst.push_back(b);
  1448.  
  1449.             cout << endl;
  1450.         }
  1451.  
  1452.         }
  1453.         else if(choice>=4 and choice<=5)
  1454.         {
  1455.             for(int i=1;i<=n;i++)
  1456.             {
  1457.             int a,b,p;
  1458.             cout<<"Enter the arrival time of P"<<i<< ": ";
  1459.             cin>>a;
  1460.             arrival.push_back(a);
  1461.  
  1462.             cout<<"Enter the burst time of P" <<i<< ": ";
  1463.             cin>>b;
  1464.             burst.push_back(b);
  1465.  
  1466.  
  1467.             cout << "Enter Priority of p" << i << ": " ;
  1468.             cin>>p;
  1469.             priority.push_back(p);
  1470.  
  1471.             cout << endl;
  1472.            }
  1473.         }
  1474.         else if(choice==6)
  1475.         {
  1476.             for(int i=1;i<=n;i++)
  1477.             {
  1478.             int a,b;
  1479.             cout<<"Enter the arrival time of P"<<i<< ": ";
  1480.             cin>>a;
  1481.             arrival.push_back(a);
  1482.  
  1483.             cout<<"Enter the burst time of P" <<i<< ": ";
  1484.             cin>>b;
  1485.             burst.push_back(b);
  1486.  
  1487.             cout << endl;
  1488.            }
  1489.  
  1490.            cout<<"Enter the time Quantum : ";
  1491.            cin>>tq;
  1492.            cout<<endl;
  1493.  
  1494.         }
  1495.         else if(choice==7)
  1496.         {
  1497.             for(int i=1;i<=n;i++)
  1498.             {
  1499.             int a,b,p;
  1500.             cout<<"Enter the arrival time of P"<<i<< ": ";
  1501.             cin>>a;
  1502.             arrival.push_back(a);
  1503.  
  1504.             cout<<"Enter the burst time of P" <<i<< ": ";
  1505.             cin>>b;
  1506.             burst.push_back(b);
  1507.  
  1508.  
  1509.             cout << "Enter Priority of p" << i << ": " ;
  1510.             cin>>p;
  1511.             priority.push_back(p);
  1512.  
  1513.             cout << endl;
  1514.            }
  1515.         }
  1516.         else if(choice==8)
  1517.         {
  1518.             for(int i=1;i<=n;i++)
  1519.             {
  1520.             int a,b,p;
  1521.             cout<<"Enter the arrival time of P"<<i<< ": ";
  1522.             cin>>a;
  1523.             arrival.push_back(a);
  1524.  
  1525.             cout<<"Enter the burst time of P" <<i<< ": ";
  1526.             cin>>b;
  1527.             burst.push_back(b);
  1528.  
  1529.  
  1530.             cout << "Enter Priority of p" << i << ": " ;
  1531.             cin>>p;
  1532.             priority.push_back(p);
  1533.  
  1534.             cout << endl;
  1535.            }
  1536.  
  1537.            cout<<"Enter the time Quantum : ";
  1538.            cin>>tq;
  1539.            cout<<endl;
  1540.         }
  1541.  
  1542.  
  1543.  
  1544.  
  1545.         if(choice==1)
  1546.         {
  1547.             fcfs(arrival,burst,1);
  1548.         }
  1549.         else if(choice==2)
  1550.         {
  1551.             non_preemptive_sjf(arrival,burst,1);
  1552.         }
  1553.  
  1554.         else if(choice==3)
  1555.         {
  1556.             preemptive_sjf(arrival,burst,1);
  1557.         }
  1558.         else if(choice==4)
  1559.         {
  1560.             non_preemptive_priority(arrival,burst,priority,1);
  1561.         }
  1562.         else if(choice==5)
  1563.         {
  1564.             preemptive_priority(arrival,burst,priority,1);
  1565.         }
  1566.         else if(choice==6)
  1567.         {
  1568.             round_robin(arrival,burst,tq,1);
  1569.         }
  1570.         else if(choice==7)
  1571.         {
  1572.             proposed_algo(arrival,burst,priority,1);
  1573.         }
  1574.         else if(choice==8)
  1575.         {
  1576.             compare_all(arrival,burst,priority,tq);
  1577.         }
  1578.  
  1579.  
  1580.         cout<<"Press any key for the home page "<<endl;
  1581.         char ch;cin>>ch;
  1582.     }
  1583. }
  1584.  
  1585. /*
  1586.  
  1587. 3
  1588. 3
  1589. 5
  1590. 1
  1591. 6
  1592. 2
  1593. 1
  1594. 12
  1595. 3
  1596. 1
  1597.  
  1598.  
  1599. //sp
  1600.  
  1601. 3
  1602. 3
  1603. 5
  1604. 1
  1605. 5
  1606. 20
  1607. 1
  1608. 6
  1609. 2
  1610. 1
  1611. 9
  1612.  
  1613.  
  1614.  
  1615. */
  1616.  
  1617.  
  1618.