作業系統任務調度問題

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   for   2014   問題   div   

作業系統任務調度問題。作業系統任務分為系統任務和使用者任務兩種。其中,系統任務的優先順序 < 50,使用者任務的優先順序 >= 50且 <= 255。優先順序大於255的為非法任務,應予以剔除。現有一任務隊列task[],長度為n,task中的元素值表示任務的優先順序,數值越小,優先順序越 高。函數scheduler實現如下功能,將task[] 中的任務按照系統任務、使用者任務依次存放到 system_task[] 數組和 user_task[] 數組中(數組中元素的值是任務在task[] 數組中的下標),並且優先順序高的任務排在前面,數組元素為-1表示結束。

例如:task[] = {0, 30, 155, 1, 80, 300, 170, 40, 99} system_task[] = {0, 3, 1, 7, -1} user_task[] = {4, 8, 2, 6, -1}

函數介面 void scheduler(int task[], int n, int system_task[], int user_task[])

 

 1 #include<stdio.h> 2 void scheduler(int task[], int n, int system_task[], int user_task[]) 3 { 4     int *x = new int[n]; 5     int i,j,k; 6     for (i=0; i < n; i++) 7         x[i] = i; 8     for (i=0; i < n-1; i++) 9         for (j=1; j < n-i; j++)10         if (task[j-1] > task[j])11         {12             int t = task[j-1];13             task[j-1] = task[j];14             task[j] = t;15             t = x[j-1];16             x[j-1] = x[j];17             x[j] = t;18         }19     for (int i=0; i < n; i++)20         printf("%d ",task[i]);21     printf("\n");22     j = 0;23     k = 0;24     for (i=0; i < n; i++)25     {26         if(task[i] < 50)27             system_task[j++] = x[i];28         else if (task[i] <= 255)29             user_task[k++] = x[i];30         else ;31     }32     system_task[j] = -1;33     user_task[k] = -1;34 }35 int main()36 {37     int task[100],sys[100],user[100],n;38     scanf("%d",&n);39     for (int i=0; i < n; i++)40         scanf("%d",&task[i]);41     scheduler(task,n,sys,user);42     for (int i=0; sys[i] != -1; i++)43         printf("%d ",sys[i]);44     printf("\n");45     for (int i=0; user[i] != -1; i++)46         printf("%d ",user[i]);47     printf("\n");48 49 }

 

作業系統任務調度問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.