Added MoveFrom().
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28284 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2008, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
* Copyright 2005-2006, Ingo Weinhold, [email protected]. All rights reserved.
|
* Copyright 2005-2008, Ingo Weinhold, [email protected].
|
||||||
*
|
*
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
@@ -144,6 +144,9 @@ class SinglyLinkedList {
|
|||||||
inline void Add(Element* element);
|
inline void Add(Element* element);
|
||||||
inline void Remove(Element* element);
|
inline void Remove(Element* element);
|
||||||
|
|
||||||
|
inline void MoveFrom(SINGLY_LINKED_LIST_CLASS_NAME* fromList);
|
||||||
|
// O(1) if either list is empty, otherwise O(n).
|
||||||
|
|
||||||
inline void RemoveAll();
|
inline void RemoveAll();
|
||||||
inline void MakeEmpty() { RemoveAll(); }
|
inline void MakeEmpty() { RemoveAll(); }
|
||||||
|
|
||||||
@@ -203,6 +206,31 @@ SINGLY_LINKED_LIST_CLASS_NAME::Remove(Element* element)
|
|||||||
elementLink->next = NULL;
|
elementLink->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SINGLY_LINKED_LIST_TEMPLATE_LIST
|
||||||
|
void
|
||||||
|
SINGLY_LINKED_LIST_CLASS_NAME::MoveFrom(SINGLY_LINKED_LIST_CLASS_NAME* fromList)
|
||||||
|
{
|
||||||
|
if (fromList->fFirst == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (fFirst == NULL) {
|
||||||
|
// This list is empty -- just transfer the head.
|
||||||
|
fFirst = fromList->fFirst;
|
||||||
|
fromList->fFirst = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Neither list is empty -- find the tail of this list.
|
||||||
|
Element* tail = fFirst;
|
||||||
|
while (Element* next = sGetLink(tail)->next)
|
||||||
|
tail = next;
|
||||||
|
|
||||||
|
sGetLink(tail)->next = fromList->fFirst;
|
||||||
|
fromList->fFirst = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// RemoveAll
|
// RemoveAll
|
||||||
SINGLY_LINKED_LIST_TEMPLATE_LIST
|
SINGLY_LINKED_LIST_TEMPLATE_LIST
|
||||||
void
|
void
|
||||||
|
|||||||
Reference in New Issue
Block a user