import vector import serialize import util fun stack():stack { var out.construct():stack return out } fun stack(in:T):stack { var out.construct():stack out.push(in) return out } obj stack (Object, Serializable) { var data: vector::vector fun construct(): *stack { data.construct() return this } fun copy_construct(other: *stack) { data.copy_construct(&other->data) } fun destruct() { data.destruct() } fun operator=(other: ref stack) { data = other.data } fun serialize(): vector::vector { return serialize::serialize(data) } fun unserialize(it: ref vector::vector, pos: int): int { var temp = vector::vector() util::unpack(temp, pos) = serialize::unserialize>(it, pos) data.copy_construct(&temp) return pos } fun push(it: ref T) { data.addEnd(it) } fun pop(): T { var toRet = data[data.size-1] data.remove(data.size-1) return toRet } fun clear() { data.clear() } fun top(): T { return data[data.size-1] } fun size(): int { return data.size } fun empty():bool { return data.size == 0 } }