# NOT RUN {
### create a new instance
# to create a new instance of the class
queue <- RQueue$new()
# the previous RQueue instance will be removed if you run
queue <- RQueue$new(0, 1, 2, collapse=list(3, 4))
# the following sentence is equivalent to the above
queue <- RQueue$new(0, 1, 2, 3, 4)
# where the numbers 0, 1, 2, 3, 4 are enqueued into the queue
### enqueue elements
# it can be one single element
queue$enqueue(5)
# it can be several elements separated by commas
# note the whole list will be one element of the queue
# because it is not passed through the collapse argument
queue$enqueue(list(a=10,b=20), "Hello world!")
# the collapse argument takes a list whose elements will be collapsed
# but the elements' names will not be saved
queue$enqueue(collapse = list(x=100,y=200))
# they can be used together
queue$enqueue("hurrah", collapse = list("RQueue",300))
### dequeue an element
# dequeue only one element at a time
val <- queue$dequeue()
# then we keep dequeuing!
while(!is.null(val)) val <- queue$dequeue()
# }
Run the code above in your browser using DataLab