fix stack
This commit is contained in:
parent
86f94df063
commit
3046baee78
26
util.d
26
util.d
@ -198,31 +198,31 @@ DLLPush(T, U)(T* list, U* node, U* nil)
|
|||||||
|
|
||||||
struct Stack(T)
|
struct Stack(T)
|
||||||
{
|
{
|
||||||
Node!(T)* first;
|
Node!(T)* top;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SPush(T, U)(T* stack, U* node, U* nil)
|
SPush(T)(Stack!(T)* stack, Node!(T)* node, Node!(T)* nil)
|
||||||
{
|
{
|
||||||
if (CheckNil(nil, stack.first))
|
if (CheckNil(nil, stack.top))
|
||||||
{
|
{
|
||||||
stack.first = node;
|
stack.top = node;
|
||||||
node.next = nil;
|
node.next = nil;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
node.next = stack.first;
|
node.next = stack.top;
|
||||||
stack.first = node;
|
stack.top = node;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
U*
|
Node!(T)*
|
||||||
SPop(T, U)(T* stack, U* nil)
|
SPop(T)(Stack!(T)* stack, Node!(T)* nil)
|
||||||
{
|
{
|
||||||
U* node = stack.first;
|
Node!(T)* node = stack.top;
|
||||||
if (!CheckNil(nil, stack.first))
|
if (!CheckNil(nil, stack.top))
|
||||||
{
|
{
|
||||||
stack.first = stack.first.next;
|
stack.top = stack.top.next;
|
||||||
}
|
}
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
@ -976,7 +976,7 @@ unittest
|
|||||||
SPush(&stack, &n3, null);
|
SPush(&stack, &n3, null);
|
||||||
|
|
||||||
u32 count = 3;
|
u32 count = 3;
|
||||||
for (auto n = stack.first; !CheckNil(null, n); n = n.next, count -= 1)
|
for (auto n = stack.top; !CheckNil(null, n); n = n.next, count -= 1)
|
||||||
{
|
{
|
||||||
assert(n.value == count);
|
assert(n.value == count);
|
||||||
}
|
}
|
||||||
@ -987,6 +987,6 @@ unittest
|
|||||||
assert(n.value == count);
|
assert(n.value == count);
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(stack.first == null);
|
assert(stack.top == null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user