-
Notifications
You must be signed in to change notification settings - Fork 0
/
cwrr.cpp
69 lines (66 loc) · 1.45 KB
/
cwrr.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//
// Created by ashita on 30/04/21.
//
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
void send(char &front);
using namespace std;
int main(){
int n;
cout<<"Enter no of queues"<<endl;
cin>>n;
int w[n];
std::deque<char> q[n];
cout<<"Enter weight of each queue"<<endl;
for(int i=0;i<n;i++){
cin>>w[i];
}
cout<<"Enter values in each queue in each line separated with ';'"<<endl;
std::string str[n];
cin>>ws;
for(int i=0;i<n;i++){
getline(cin,str[i]);
}
int check=0;
for(int i=0;i<n;i++){
std::string del=";";
size_t pos = 0;
char* token;
std::string temp;
while ((pos = str[i].find(del)) != std::string::npos) {
temp = str[i].substr(0, pos);
token=const_cast<char*>(temp.c_str());
//std::cout << token[0] << std::endl;
q[i].push_back(token[0]);
check++;
str[i].erase(0, pos + del.length());
}
}
int c;
cout<<"Output:Processes per cycle:"<<endl;
while(check-->0){
for(int i=0;i<n;i++){
c=0;
while((!q[i].empty()) &&(c<w[i])){
send(q[i].front());
q[i].pop_front();
check--;
c+=1;
}
}
cout<<endl;
}
return 0;
}
void send(char &front) {
std::cout<<front<<" ";
}
/*Input
3
5 2 3
A;B;C;D;E;F;G;
U;V;W;
X;Y;
*/