astl
Version:
AssemblyScript-STL (Standard Template Library, migrated from the C++)
54 lines (46 loc) • 1.09 kB
text/typescript
import { Vector } from "./Vector";
export class Stack<T>
{
private data_: Vector<T>;
/* ---------------------------------------------------------
CONSTURCTORS
--------------------------------------------------------- */
public constructor()
{
this.data_ = new Vector<T>();
}
public pop(): void
{
this.data_.pop_back();
}
public push(value: T): void
{
this.data_.push_back(value);
}
public swap(obj: Stack<T>): void
{
const data: Vector<T> = this.data_;
this.data_ = obj.data_;
obj.data_ = data;
}
/* ---------------------------------------------------------
ACCESSORS
--------------------------------------------------------- */
public size(): usize
{
return this.data_.size();
}
public empty(): boolean
{
return this.data_.empty();
}
public top(): T
{
return this.data_.back();
}
}