Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Stack/D/stack.d
Normal file
26
Task/Stack/D/stack.d
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import std.array;
|
||||
|
||||
class Stack(T) {
|
||||
private T[] items;
|
||||
|
||||
@property bool empty() { return items.empty(); }
|
||||
|
||||
void push(T top) { items ~= top; }
|
||||
|
||||
T pop() {
|
||||
if (this.empty)
|
||||
throw new Exception("Empty Stack.");
|
||||
auto top = items.back;
|
||||
items.popBack();
|
||||
return top;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
auto s = new Stack!int();
|
||||
s.push(10);
|
||||
s.push(20);
|
||||
assert(s.pop() == 20);
|
||||
assert(s.pop() == 10);
|
||||
assert(s.empty());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue