Перенос страниц
This commit is contained in:
parent
4d57446057
commit
4c954c9186
129 changed files with 14 additions and 15 deletions
|
@ -0,0 +1,50 @@
|
|||
import std.array;
|
||||
|
||||
interface Stack(T)
|
||||
{
|
||||
@property bool empty();
|
||||
@property ref T top();
|
||||
void push(T value);
|
||||
void pop();
|
||||
}
|
||||
|
||||
class StackImpl(T) : Stack!T
|
||||
{
|
||||
private T[] _store;
|
||||
|
||||
@property bool empty()
|
||||
{
|
||||
return _store.empty;
|
||||
}
|
||||
|
||||
@property ref T top()
|
||||
{
|
||||
assert(!empty);
|
||||
return _store.back;
|
||||
}
|
||||
|
||||
void push(T value)
|
||||
{
|
||||
_store ~= value;
|
||||
}
|
||||
|
||||
void pop()
|
||||
{
|
||||
assert(!empty);
|
||||
_store.popBack();
|
||||
}
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
auto stack = new StackImpl!int;
|
||||
assert(stack.empty);
|
||||
stack.push(3);
|
||||
assert(stack.top == 3);
|
||||
stack.push(5);
|
||||
assert(stack.top == 5);
|
||||
stack.pop();
|
||||
assert(stack.top == 3);
|
||||
stack.pop();
|
||||
assert(stack.empty);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue