Learn R Programming

sybil (version 2.2.0)

sybilStack: A Data Type Providing Stack (LIFO) And Queue (FIFO) Functionality

Description

These functions implement simple stack or queue functionality.

Usage

stinit(stname)
  stclear(stname)
  stpush(stname, value)
  stpop(stname)
  stunshift(stname, value)
  stshift(stname)
  stseek(stname)
  stfirst(stname)
  stlist(stname)
  stlength(stname)
  stexists(stname)

Arguments

stname

A single character string, giving the name of the stack or queue.

value

Value to add to the stack or queue.

Value

The functions stpop and stshift return the last/first element of the stack invisibly. The functions stseek and stfirst just return the last/first element.

Details

The funtion stinit creates an empty stack named stname.

The funtion stclear removes the stack named stname.

The funtion stpush appends element value at the end of the stack named stname.

The funtion stpop removes the last element of the stack named stname and returns it invisible.

The funtion stunshift appends element value at the beginning of the stack stname.

The funtion stshift removes the first element of the stack named stname and returns it invisible.

The funtion stseek returns the last element of the stack named stname but does not remove it.

The funtion stfirst returns the first element of the stack named stname but does not remove it.

The funtion stlist returns the stack named stname as list.

The funtion stlength returns the number of elements stored in the stack named stname.

The funtion stexists returns TRUE if a stack named stname exists, otherwise FALSE.

Examples

Run this code
# NOT RUN {
  ## initialize empty stack named test
  stinit("test")

  ## add a few elemets
  stpush("test", 9)
  stpush("test", 3)
  stpush("test", 7)

  ## get last element
  stpop("test")

  ## remove stack
  stclear("test")
# }

Run the code above in your browser using DataLab