#i nclude <iostream>
using namespace std;
void scheduler(int task[], int n, int system_task[], int user_task[])
{
if (NULL == task || NULL == system_task || NULL == user_task || n <= 0)
{
return;
}
int j = 0, k = 0;
for (int i = 0; i < n; i++)
{
if (task[i] < 50)
{
if (j == 0)
{
system_task[j++] = i;
}
else
{
if (task[i] < task[system_task[j - 1]])
{
int m;
for (m = j - 1; task[system_task[m]] > task[i] && m >= 0; m--)
{
system_task[m + 1] = system_task[m];
}
system_task[m + 1] = i;
}
else
{
system_task[j] = i;
}
++j;
}
}
if (task[i] >= 50 && task[i] <= 255)
{
if (k == 0)
{
user_task[k++] = i;
}
else
{
if (task[i] < task[user_task[k - 1]])
{
int m;
for (m = k - 1; m >= 0 && task[user_task[m]] > task[i]; m--)
{
user_task[m + 1] = user_task[m];
}
user_task[m + 1] = i;
}
else
{
user_task[k] = i;
}
++k;
}
}
}
user_task[k] = -1;
system_task[j] = -1;
}