We can use the length
method to get the number of elements present in the CircularDeque
.
Note: ACircularDeque
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.
length(deque_object)
This method takes the CircularDeque
object as an argument.
This method returns the number of elements present in the CircularDeque
.
The code below demonstrates how to get the number of elements present in the CircularDeque
object.
using DataStructures #create a new CircularDeque object for 5 elements deque = CircularDeque{Int}(5); push!(deque,10); push!(deque, 20); push!(deque, 30); println("Deque -> $(deque)") println("Number of elements in the deque $(length(deque))")
CircularDeque
object with the name deque
. For this object, we set the capacity as 5, meaning that it can hold 5 elements. Also, we set the elements of deque
to be the int
datatype.10
, 20
, and 30
to deque
using the push!
method.length
method to get the number of elements present in the deque
object. In our case, we'll get 3
as a result.RELATED TAGS
CONTRIBUTOR
View all Courses