Stack: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: syntax coloured, replaced parts 2 & 3 with using the builtins) |
|||
Line 2,462: | Line 2,462: | ||
{{trans|Swift}} |
{{trans|Swift}} |
||
<lang dyalect>type Stack |
<lang dyalect>type Stack() { |
||
var xs = [] |
|||
} |
|||
static func Stack.Stack() => Stack.Cons([]) |
|||
func Stack.IsEmpty() => |
func Stack.IsEmpty() => ini.xs.Length() == 0 |
||
func Stack.Peek() => |
func Stack.Peek() => ini.xs[ini.xs.Length() - 1] |
||
func Stack.Pop() { |
func Stack.Pop() { |
||
var e = |
var e = ini.xs[ini.xs.Length() - 1] |
||
ini.xs.RemoveAt(ini.xs.Length() - 1) |
|||
return e |
return e |
||
} |
} |
||
func Stack.Push(item) => |
func Stack.Push(item) => ini.xs.Add(item) |
||
var stack = Stack() |
var stack = Stack() |