Created
April 24, 2019 03:02
-
-
Save anfederico/2f92d3c36f4c887f00998641484dc6e7 to your computer and use it in GitHub Desktop.
A push/pop capable vector in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(R6) | |
pvector <- R6Class("pvector", list( | |
values = NULL, | |
initialize = function(values=c()) { | |
self$values <- values | |
}, | |
pop = function() { | |
if (length(self$values) > 0) { | |
popped.value <- self$values[1] | |
self$values <- self$values[-1] | |
return(popped.value) | |
} | |
}, | |
push = function(pushed.values) { | |
self$values <- c(self$values, pushed.values) | |
} | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment