CAtlList::SwapElements

Appelez cette méthode pour échanger des éléments dans la liste.

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

Paramètres

  • pos1
    La première valeur de POSITION.

  • pos2
    La deuxième valeur de POSITION.

Notes

Permute les éléments aux deux emplacements spécifiés.Dans les versions debug, un échec d'assertion se produit si l'une ou l'autre des valeurs de position est égale à la valeur NULL.

Exemple

// 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);   

Configuration requise

Header: atlcoll.h

Voir aussi

Référence

Classe de CAtlList

CAtlList::MoveToHead

CAtlList::MoveToTail