Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

eltype
circulardeque
julia
communitycreator

How to use the eltype method with CircularDeque in Julia

Programming Bytes

Overview

The eltype method is used to get the type of items of the CircularDeque object.

Note: The CircularDeque object object 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

eltype!deque_object)
Julia eltype function syntax

Parameter

This method takes a CircularDeque object and the values to be inserted as arguments.

Return value

This method returns the data type of the elements of the CircularDeque object.

Example

using DataStructures

#create a new CircularDeque object for 5 elements 
deque = CircularDeque{Int}(5);

push!(deque,2);
push!(deque, 3);
push!(deque, 4);

println("\nDeque ->  $(deque)")

# print the data type of the elements of the deque
println("\nDeque ->  $(eltype(deque))")
Using the eltype method to get the datatype of the CircularDeque elements

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.
  • Lines 6–8: We add three integer elements, 2,3, and 4, to deque using the push! method.
  • Line 13: We use the eltype method to get the datatype of the deque elements. We get Int64 as a result.

RELATED TAGS

eltype
circulardeque
julia
communitycreator
RELATED COURSES

View all Courses

Keep Exploring