CAtlList::SwapElements

调用此方法交换列表中的元素。

void SwapElements(
   POSITION pos1,
   POSITION pos2 
) throw( );

参数

  • pos1
    第一个位置值。

  • pos2
    第二个位置值。

备注

交换元素在指定的两个位置。如果任一位置值与NULL,相等在调试版本中,断言失败将发生。

示例

// Define the integer list
CAtlList<int> myList;

// Populate the list
for (int i = 0; i < 100; i++)
{
   myList.AddHead(i);
}

// Order is: 99, 98, 97, 96...
ATLASSERT(myList.GetHead() == 99);
ATLASSERT(myList.GetTail() == 0);

// Perform a crude bubble sort
for (int j = 0; j < 100; j++)
{
   for(int i = 0; i < 99; i++)
   {
      if (myList.GetAt(myList.FindIndex(i)) > 
         myList.GetAt(myList.FindIndex(i+1)))
      {
         myList.SwapElements(myList.FindIndex(i), myList.FindIndex(i+1));
      }
   }
}

// Order is: 0, 1, 2, 3...
ATLASSERT(myList.GetHead() == 0);
ATLASSERT(myList.GetTail() == 99);   

要求

Header: atlcoll.h

请参见

参考

CAtlList选件类

CAtlList::MoveToHead

CAtlList::MoveToTail