# 在C＃中交替对列表进行排序或重新排序

``````List<int>() { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
``````

``````List<int>() { 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 };
``````

``````List<int>() { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0 };
``````

List SlotMapLP1 = new List（）{0，1，1，1，1，1，1，1，1，1，0，1，0，1，0，1，0，0，0，0，0， 0，0，0，0};

``````int i = 0, j = 0, k = 0, waferCount = 0, loopCtr = 0;
for (i = 0; i < SlotMapLP1.Count; i++ )
{
if (SlotMapLP1[i] == 1)
waferCount++;
}

List<int> ptnOne = new List<int>(SlotMapLP1);
List<int> ptnTwo = new List<int>(SlotMapLP1);

j = ptnOne.Count - 1;
while (j >= 0 && loopCtr <= waferCount) //list will start to traverse from right to left
{
if ((ptnOne[j] == 0 && (j + 1) % 2 > 0))
{
k = j - 1;
while (k >= 0)
{
if (ptnOne[k] == 1 && (ptnOne[k] != ptnOne[j]))
{
ExtensionMethods.Swap(ptnOne, k, j); //swap the two items
loopCtr++;
break;
}
k--;
}
}
else
{
if (j == 0 || j + 1 == ptnOne.Count) break;
if (ptnOne[j - 1] == 0 && ptnOne[j + 1] == 1)
{
k = j - 1;
while (k >= 0)
{
if (ptnOne[k] == 0 && (ptnOne[k] != ptnOne[j]))
{
ExtensionMethods.Swap(ptnOne, j, k); //swap the two items
loopCtr++;
break;
}
k--;
}
}
else
{
k = j - 1;
while (k >= 0)
{
if (ptnOne[k] == 1 && (ptnOne[k] != ptnOne[j]))
{
ExtensionMethods.Swap(ptnOne, j, k); //swap the two items
loopCtr++;
break;
}
k--;
}
}
}
j--;
}

loopCtr = 0; j = 0; k = 0;
while (j < ptnTwo.Count && loopCtr <= waferCount)//list will start to traverse from left to right
{
if (ptnTwo[j] == 0 && (j + 1) % 2 > 0)
{
k = j + 1;
while (k < ptnTwo.Count)
{
if (ptnTwo[k] == 1 && (ptnTwo[k] != ptnTwo[j]))
{
ExtensionMethods.Swap(ptnTwo, j, k); //swap the two items
loopCtr++;
break;
}
k++;
}
}
else
{
if (j == 0 || j + 1 == ptnOne.Count) break;
if (ptnTwo[j + 1] == 0 && ptnTwo[j - 1] == 1)
{
k = j + 1;
while (k < ptnTwo.Count)
{
if (ptnTwo[k] == 0 && (ptnTwo[k] != ptnTwo[j]))
{
ExtensionMethods.Swap(ptnTwo, j, k); //swap the two items
loopCtr++;
break;
}
k++;
}
}
else
{
k = j + 1;
while (k < ptnTwo.Count)
{
if (ptnTwo[k] == 1 && (ptnTwo[k] != ptnTwo[j]))
{
ExtensionMethods.Swap(ptnTwo, j, k); //swap the two items
loopCtr++;
break;
}
k++;
}
}
}
j++;
}
``````

1000000000000000000000000

1010000000000000000000000

3个：

1010100000000000000000000

1. 令n =列表中的个数
2. 如果没有，则模式A和B都只有25个零。
3. 其他建立长度为n * 2-1的交替模式。
4. 对于模式A，将25-（n * 2-1）个零和交替的模式连接起来。
5. 对于模式B，请连接交替模式和25-（n * 2-1）零。（或图案A的反面）

0 条评论