-1

ユーザーにプロセス数、プロセス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;
}
4

2 に答える 2

0

並べ替えには、任意の並べ替えアルゴリズム (バブル 並べ替え、挿入並べ替え、ヒープ並べ替えなど) を適用できますが、隣接する要素を比較する場合は、それらの優先度を比較してください。何かのようなもの

if(process[index1].Prio < process[index2].Prio)
于 2013-11-14T13:42:11.643 に答える