How to use the isempty method of CircularDeque in Julia
Overview
The isempty method is used to check if a CircularDeque object is empty.
Note:CircularDequeis 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.
Syntax
isempty(deque_object)
Parameter
This method takes a CircularDeque object as an argument.
Return value
This method returns true if the CircularDeque object contains no elements. Otherwise, it returns false.
Example
using DataStructures#create a new CircularDeque object for 5 elementsdeque = CircularDeque{Int}(5);println("Deque -> $(deque)")println("Is Deque empty : $(isempty(deque))")push!(deque,10);push!(deque, 20);push!(deque, 30);println("\nDeque -> $(deque)")println("Is Deque empty : $(isempty(deque))")
Explanation
- Line 4: We create a
CircularDequeobject with the namedeque. For this object, we set the capacity as5, meaning it can hold 5 elements. Also, we set the elements ofdequeto be an integer datatype. - Line 7: We use the
isemptymethod to check ifdequeis empty. In our case,dequecontains no element, so it retunstrue. - Lines 9–11: We add three integer elements,
10,20,30, todequeusing thepush!method. - Line 14: We use the
isemptymethod to check ifdequeis empty. In our case,dequecontains three elements, so it returnsfalse.