Category:Pluto-queue
Library
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
This is an example of a library. You may see a list of other libraries used on Rosetta Code at Category:Solutions by Library.
Pluto-queue is a module which adds support for efficient queue data structures to the Pluto programming language. There are 4 classes: stack, queue, deque and pqueue. The implementations minimize explicit insertions or removals by manipulating pointers to the first and last elements.
To install:
- Copy the source into a file named
queue.pluto.
- The file needs to be in the same directory as your program.
Then, add require "queue" to your program. Example usage:
require "queue" -- don't assign this to a variable
local s = new stack()
s:push(1, 2)
print(s:pop()) --> 2
print(s:size()) --> 1
print()
local q = new queue()
q:push(1, 2)
print(q:pop()) --> 1
print(q:size()) --> 1
print()
local d = new deque()
d:pushBack(1)
d:pushFront(2)
print(d:popBack()) --> 1
print(d:popFront()) --> 2
print(d:empty()) --> true
print()
local p = new pqueue()
p:push(1, "lowest")
p:push(2, "highest")
print(p:peek()) --> highest
print(p:size()) --> 2
Pages in category "Pluto-queue"
The following 7 pages are in this category, out of 7 total.