tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
30
Task/Queue-Definition/R/queue-definition-3.r
Normal file
30
Task/Queue-Definition/R/queue-definition-3.r
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
library(proto)
|
||||
|
||||
fifo <- proto(expr = {
|
||||
l <- list()
|
||||
empty <- function(.) length(.$l) == 0
|
||||
push <- function(., x)
|
||||
{
|
||||
.$l <- c(.$l, list(x))
|
||||
print(.$l)
|
||||
invisible()
|
||||
}
|
||||
pop <- function(.)
|
||||
{
|
||||
if(.$empty()) stop("can't pop from an empty list")
|
||||
.$l[[1]] <- NULL
|
||||
print(.$l)
|
||||
invisible()
|
||||
}
|
||||
})
|
||||
|
||||
#The following code provides output that is the same as the previous example.
|
||||
fifo$empty()
|
||||
fifo$push(3)
|
||||
fifo$push("abc")
|
||||
fifo$push(matrix(1:6, nrow=2))
|
||||
fifo$empty()
|
||||
fifo$pop()
|
||||
fifo$pop()
|
||||
fifo$pop()
|
||||
fifo$pop()
|
||||
Loading…
Add table
Add a link
Reference in a new issue