我需要交换两个非重复序列(数组)中的前 n 个元素,其中 n 是一个随机整数。
序列1:1 4 5 6 9 8 2 3 7
序列 2:3 9 1 2 8 7 4 5 6
如果 n = 4
序列1:3 9 1 2 | 9 8 2 3 7
序列 2:1 4 5 6 | 8 7 4 5 6
现在我需要通过替换“|”之后的重复数字来修复序列。
这该怎么做?
这是我的努力..
for(left1 = 0; left1<pivot; left1++)
{
for(right1 = pivot; right1 < no_jobs; right1++)
{
if(S1->sequence[left1] == S1->sequence[right1])
{
for(left2 = 0; left2<pivot; left2++)
{
for(right2 = pivot; right2<no_jobs; right2++)
{
if(S2->sequence[left2] == S2->sequence[right2])
{
swap_temp = S1->sequence[right1];
S1->sequence[right1] = S2->sequence[right2];
S2->sequence[right2] = swap_temp;
break;
}
}
}
}
}
}