Learn R Programming

dequer (version 2.0-2)

sep: sep

Description

Spliot one object (queue/stack/deque) into two of the same type. NOTE: this function operates via side-effects AND has a return.

Usage

sep(x, k)

Arguments

x

A deque.

k

Index to split the deque at.

Value

A deque, stack, or queue (depending on the input)

Details

Operates via side-effects ALTHOUGH THERE IS A NON-NULL RETURN; see examples for clarification on usage.

The split occurs after index k. So if the input x has, say, elements 1 to n, then after running sep(x, k), x will have elements 1 to k, and the return will have values k+1, k+2, ..., n.

Examples

Run this code
# NOT RUN {
library(dequer)
s <- stack()
for (i in 1:5) push(s, i)

### Split s into 2 stacks holding: (s) the first 3, and (s_last_2) last 2 elements
s_last_2 <- sep(s, 3)

str(s)
str(s_last_5)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab