Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

isempty
circulardeque
julia
communitycreator

How to use the isempty method of CircularDeque in Julia

Programming Bytes

Overview

The isempty method is used to check if a CircularDeque object is empty.

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.

Syntax

isempty(deque_object)
Julia isempty function syntax

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 elements 
deque = 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))")
Using the isempty method to check if the CircularDeque is empty

Explanation

  • Line 4: We create a 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.
  • Line 7: We use the isempty method to check if deque is empty. In our case, deque contains no element, so it retuns true.
  • Lines 9–11: We add three integer elements, 10,20,30, to deque using the push! method.
  • Line 14: We use the isempty method to check if deque is empty. In our case, deque contains three elements, so it returns false.

RELATED TAGS

isempty
circulardeque
julia
communitycreator
RELATED COURSES

View all Courses

Keep Exploring