mirror of
https://github.com/ProgramSnail/Lama.git
synced 2025-12-06 06:48:48 +00:00
Added queue to stdlib
This commit is contained in:
parent
4cb462c2a8
commit
ddb45a496f
2 changed files with 28 additions and 0 deletions
|
|
@ -18,6 +18,8 @@ $(BDIR)/Fun.o: $(BDIR)/Ref.o
|
|||
|
||||
$(BDIR)/Data.o: $(BDIR)/Ref.o $(BDIR)/Collection.o
|
||||
|
||||
$(BDIR)/Queue.o: $(BDIR)/List.o
|
||||
|
||||
$(BDIR)/Collection.o: $(BDIR)/List.o $(BDIR)/Ref.o
|
||||
|
||||
$(BDIR)/Array.o: $(BDIR)/List.o
|
||||
|
|
|
|||
26
stdlib/Queue.lama
Normal file
26
stdlib/Queue.lama
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue