mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
27 lines
431 B
Text
27 lines
431 B
Text
|
|
import List;
|
||
|
|
|
||
|
|
fun emptyQueue () {
|
||
|
|
[{}, {}]
|
||
|
|
}
|
||
|
|
|
||
|
|
fun isEmptyQueue (q) {
|
||
|
|
case q of
|
||
|
|
[{}, {}] -> true
|
||
|
|
| _ -> false
|
||
|
|
esac
|
||
|
|
}
|
||
|
|
|
||
|
|
fun enqueue ([pop, push], x) {
|
||
|
|
[pop, x : push]
|
||
|
|
}
|
||
|
|
|
||
|
|
fun dequeue ([pop, push]) {
|
||
|
|
case pop of
|
||
|
|
x : pop -> [[pop, push], x]
|
||
|
|
| _ -> case push of
|
||
|
|
{} -> failure ("dequeueing from empty queue\n")
|
||
|
|
| _ -> dequeue ([reverse (push), {}])
|
||
|
|
esac
|
||
|
|
esac
|
||
|
|
}
|