Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
|
|
@ -1,27 +1,27 @@
|
|||
# The usual Scheme way : build a function that takes commands as parameters (it's like message passing oriented programming)
|
||||
queue <- function() {
|
||||
v <- list()
|
||||
f <- function(cmd, val=NULL) {
|
||||
if(cmd == "push") {
|
||||
v <<- c(v, val)
|
||||
invisible()
|
||||
} else if(cmd == "pop") {
|
||||
if(length(v) == 0) {
|
||||
stop("empty queue")
|
||||
} else {
|
||||
x <- v[[1]]
|
||||
v[[1]] <<- NULL
|
||||
x
|
||||
}
|
||||
} else if(cmd == "length") {
|
||||
length(v)
|
||||
} else if(cmd == "empty") {
|
||||
length(v) == 0
|
||||
} else {
|
||||
stop("unknown command")
|
||||
}
|
||||
}
|
||||
f
|
||||
v <- list()
|
||||
f <- function(cmd, val=NULL) {
|
||||
if(cmd == "push") {
|
||||
v <<- c(v, val)
|
||||
invisible()
|
||||
} else if(cmd == "pop") {
|
||||
if(length(v) == 0) {
|
||||
stop("empty queue")
|
||||
} else {
|
||||
x <- v[[1]]
|
||||
v[[1]] <<- NULL
|
||||
x
|
||||
}
|
||||
} else if(cmd == "length") {
|
||||
length(v)
|
||||
} else if(cmd == "empty") {
|
||||
length(v) == 0
|
||||
} else {
|
||||
stop("unknown command")
|
||||
}
|
||||
}
|
||||
f
|
||||
}
|
||||
|
||||
# Create two queues
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue