all tasks

This commit is contained in:
Ingy döt Net 2013-04-11 01:07:29 -07:00
parent b83f433714
commit 68f8f3e56b
14735 changed files with 178959 additions and 0 deletions

26
Task/Stack/D/stack.d Normal file
View 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());
}