private void exchange(string[] argv)
{
int bottom = this.firstNonopt;
int middle = this.lastNonopt;
int top = this.optind;
string tem;
while (top > middle && middle > bottom)
{
if (top - middle > middle - bottom)
{
// Bottom segment is the short one.
int len = middle - bottom;
int i;
// Swap it with the top part of the top segment.
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[top - (middle - bottom) + i];
argv[top - (middle - bottom) + i] = tem;
}
// Exclude the moved bottom segment from further swapping.
top -= len;
}
else
{
// Top segment is the short one.
int len = top - middle;
int i;
// Swap it with the bottom part of the bottom segment.
for (i = 0; i < len; i++)
{
tem = argv[bottom + i];
argv[bottom + i] = argv[middle + i];
argv[middle + i] = tem;
}
// Exclude the moved top segment from further swapping.
bottom += len;
}
}
// Update records for the slots the non-options now occupy.
this.firstNonopt += (this.optind - this.lastNonopt);
this.lastNonopt = this.optind;
}