The pushfirst!
method is used to add an element at the beginning of the CircularDeque
object.
Note:CircularDeque
is a double-ended queue implementation using a circular buffer of fixed capacity (while creating the deque, the capacity should be provided). It supports insertion and deletion on both ends.
pushfirst!(deque_object, items...) -> collection
This method takes an CircularDeque
object and the values to be inserted as arguments.
This method returns the CircularDeque
object, which is passed in the arguments.
using DataStructures#create a new CircularDeque object for 5 elementsdeque = CircularDeque{Int}(5);push!(deque,2);push!(deque, 3);push!(deque, 4);println("\nDeque -> $(deque)")# insert 0 and 1 at the beginning of the dequepushfirst!(deque, 0, 1);println("\nDeque -> $(deque)")
CircularDeque
object with the name deque
. For this object, we set the capacity as 5
, meaning it can hold 5 elements. Also, we set the elements of deque
to be an integer datatype.2
,3
, and 4
, to deque
using the push!
method.pushfirst!
method to add two elements, 0,1
, at the beginning of the deque
object. After calling this method, the elements of deque
will be 0,1,2,3,4
.