mirror of
https://github.com/reactos/reactos.git
synced 2025-08-03 20:05:41 +00:00
[ATL] Add CAtlList::SwapElements
This commit is contained in:
parent
9d7d3314b3
commit
08d808cc44
2 changed files with 112 additions and 6 deletions
|
@ -494,6 +494,8 @@ public:
|
|||
_In_opt_ POSITION posStartAfter = NULL) const;
|
||||
POSITION FindIndex(_In_ size_t iElement) const;
|
||||
|
||||
void SwapElements(POSITION pos1, POSITION pos2);
|
||||
|
||||
private:
|
||||
CNode* CreateNode(
|
||||
INARGTYPE element,
|
||||
|
@ -809,6 +811,45 @@ POSITION CAtlList< E, ETraits >::FindIndex(_In_ size_t iElement) const
|
|||
return (POSITION)Node;
|
||||
}
|
||||
|
||||
template<typename E, class ETraits>
|
||||
void CAtlList< E, ETraits >::SwapElements(POSITION pos1, POSITION pos2)
|
||||
{
|
||||
if (pos1 == pos2)
|
||||
return;
|
||||
|
||||
|
||||
CNode *node1 = (CNode *)pos1;
|
||||
CNode *node2 = (CNode *)pos2;
|
||||
|
||||
CNode *tmp = node1->m_Prev;
|
||||
node1->m_Prev = node2->m_Prev;
|
||||
node2->m_Prev = tmp;
|
||||
|
||||
if (node1->m_Prev)
|
||||
node1->m_Prev->m_Next = node1;
|
||||
else
|
||||
m_HeadNode = node1;
|
||||
|
||||
if (node2->m_Prev)
|
||||
node2->m_Prev->m_Next = node2;
|
||||
else
|
||||
m_HeadNode = node2;
|
||||
|
||||
tmp = node1->m_Next;
|
||||
node1->m_Next = node2->m_Next;
|
||||
node2->m_Next = tmp;
|
||||
|
||||
if (node1->m_Next)
|
||||
node1->m_Next->m_Prev = node1;
|
||||
else
|
||||
m_TailNode = node1;
|
||||
|
||||
if (node2->m_Next)
|
||||
node2->m_Next->m_Prev = node2;
|
||||
else
|
||||
m_TailNode = node2;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CAtlist private methods
|
||||
|
@ -897,4 +938,4 @@ private:
|
|||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue