add DLLInsert
This commit is contained in:
parent
b026f78ec2
commit
6757559089
32
util.d
32
util.d
@ -215,6 +215,36 @@ DLLPush(T, U)(T* list, U* node, U* nil)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DLLInsert(T, U)(T* list, U* node, U* prev, U* nil)
|
||||||
|
{
|
||||||
|
node.next = node.prev = nil;
|
||||||
|
|
||||||
|
if(CheckNil(nil, list.first) && CheckNil(nil, list.last))
|
||||||
|
{
|
||||||
|
assert(CheckNil(nil, prev));
|
||||||
|
list.first = list.last = node;
|
||||||
|
}
|
||||||
|
else if(list.first == prev && list.last == prev)
|
||||||
|
{
|
||||||
|
list.last = node;
|
||||||
|
node.prev = prev;
|
||||||
|
prev.next = node;
|
||||||
|
}
|
||||||
|
else if(list.last == prev)
|
||||||
|
{
|
||||||
|
prev.next = node;
|
||||||
|
node.prev = prev;
|
||||||
|
list.last = node;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
node.next = prev.next;
|
||||||
|
node.prev = prev;
|
||||||
|
prev.next = node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Stack(T)
|
struct Stack(T)
|
||||||
{
|
{
|
||||||
Node!(T)* top;
|
Node!(T)* top;
|
||||||
@ -986,6 +1016,8 @@ unittest
|
|||||||
DLLRemove(&list, &nodes[1], null);
|
DLLRemove(&list, &nodes[1], null);
|
||||||
|
|
||||||
TestDLList(&list, res1);
|
TestDLList(&list, res1);
|
||||||
|
|
||||||
|
DLLInsert(&list, &nodes[1], &nodes[0], null);
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // MemCpy
|
{ // MemCpy
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user