DS Stacks

A ds_stack is a last-in-first-out data structure.

A stack data structure is a so called last-in-first-out (LIFO) structure. You can push values onto a stack and the remove them again by popping them from the stack, and the value that was pushed on the stack most recently is the first to be popped from it again (just think of a stack of coins, where each coin that you add has to be removed again first before you can get to the rest of the coins beneath). Stacks are often used when there are interrupts to handle, or when having recursive functions, or even when constructing a rudimentary AI for your games.

NOTE: As with all dynamic resources, data structures take up memory and so should always be destroyed when no longer needed to prevent memory leaks which will slow down and eventually crash your game.

The following functions exist that deal with DS Stacks.

  1. ds_stack_create
  2. ds_stack_destroy
  3. ds_stack_clear
  4. ds_stack_empty
  5. ds_stack_size
  6. ds_stack_copy
  7. ds_stack_top
  8. ds_stack_pop
  9. ds_stack_push
  10. ds_stack_read
  11. ds_stack_write
NOTE: if you need to check if a data structure exists, you can use the ds_exists() function.


Back: Data Structures
Next: Queues
© Copyright YoYo Games Ltd. 2019 All Rights Reserved