#include<iostream>
#include<list>
using namespace std;
void Output(list<int> PCB_list) {
cout<<"ID of process in queue is:"<<endl;
for(int x : PCB_list) cout<<x<<' ';
cout<<'\n';
}
int main() {
list<int> PCB_list;
cout<<"Please input PID in order, end with -1 : \n";
int x;
while(cin>>x,x!=-1) PCB_list.push_back(x);
Output(PCB_list);
cout<<"Please enter the process number you want to delete, end with -1 : \n";
while(cin>>x,x!=-1) PCB_list.remove(x);
Output(PCB_list);
return 0;
} 应要求强化了一下
#include <algorithm>
#include <iostream>
#include <list>
using namespace std;
void Output(list<int> a) {
cout << "ID of process in queue is:" << endl;
for (int x : a) cout << x << ' ';
cout << endl;
}
int main() {
list<int> PCB_list;
cout << "Please input PID in order, end with -1 : \n";
int x;
while (cin >> x, x != -1) {
if (PCB_list.empty())
PCB_list.push_back(x);
else {
if (find(PCB_list.begin(), PCB_list.end(), x) == PCB_list.end())
PCB_list.push_back(x);
else
cout << "Error: PID existing" << endl;
}
Output(PCB_list);
}
cout << "Please input PID you want to insert in front, end with -1 : \n";
while (cin >> x, x != -1) {
if (find(PCB_list.begin(), PCB_list.end(), x) == PCB_list.end())
PCB_list.push_front(x);
else
cout << "Error: PID existing" << endl;
Output(PCB_list);
}
cout << "Please enter the process number you want to delete, end with -1 : "
<< endl;
while (cin >> x, x != -1) {
if (find(PCB_list.begin(), PCB_list.end(), x) != PCB_list.end())
PCB_list.remove(x);
else
cout << "Error: PID does not exist" << endl;
Output(PCB_list);
}
return 0;
} 
京公网安备 11010502036488号