我需要让用户插入进程数、进程 ID 和等待时间,然后我必须根据进程优先级进行排序、比较和打印我是 C 新手,我不知道该怎么做 感谢任何帮助 谢谢提前*/
struct Process {
int Id;
int Prio;
int Time;
};
struct Process process[100];
void init() {
printf("Enter number of processes:\n ");
scanf("%d",&n);
while(n<3) {
printf("Number has to be grater than 2\n");
scanf("%d",&n);
}
for (int x=0; x<n; x++) {
printf("Process %d ID:\n ", x+1);
scanf("%d",&process[x].Id);
printf("Process %d priority:\n ", x+1);
scanf("%d",&process[x].Prio);
printf("Process %d time:\n ", x+1);
scanf("%d",&process[x].Time);
}
}
void priority() {
for (int x=0; x<n; x++) {
printf("%d",process[x].Id);
printf(" %d",process[x].Prio);
printf(" %d\n\n",process[x].Time);
}
}
void line(int dashes) {
for(int x=1;x<dashes;x++) {
printf("-");
}
}
void display() {
printf("\n");
printf(" PROCESS SCHEDULING\n");
line(90);
printf("\n");
printf("ID");
printf(" PRIORITY");
printf(" WAITING TIME");
line(90);
printf("\n\n");
}
int main() {
init();
display();
priority();
return 0;
}