共用方式為


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