Working with queues
Like stacks, queues are collections of elements or objects of the same type. The length of any queue is variable just like a stack, meaning its size changes as elements are added or removed. However, queues follow the first-in-first-out (FIFO) model, meaning the first element in the queue is the first accessible element. You should note that queues can store null
and duplicate values but can't be initialized with elements when they're created. The code in this section is for example purposes only, and is not included in our game.
A queue variable declaration needs to have the following:
- The
Queue
keyword, its element type between left and right arrow characters, and a unique name - The
new
keyword to initialize the queue in memory, followed by theQueue
keyword and element type between arrow characters - A pair of parentheses capped off by a semicolon
In blueprint form, a queue looks as follows:
Queue<elementType...