How to return objecr array index in Julia

I am trying to return the index of a selected item in my Vector collection

type Node
       name::AbstractString
       value::Int
       left::Nullable{Node}
       right::Nullable{Node}

       Node(name::AbstractString, value::Int) = new(name, value, Nullable{Node}(), Nullable{Node}())
end

function minimal(nodes::Vector{Node})
                minnode=Nullable{Node}()
                minval = nodes[1].value
                    for f in nodes
                        if f.value< minval
                            minval= f.value
                            minnode = f
                        end
                    end
                return find(nodes .== minnode)
end

The problem, of course, find(nodes .== minnode)is how can I return the index of this element

-1
source share
1 answer

The function seems to be too crowded, this would not be enough:

findmin([i.value for i in nodes])[2]

eg. for

nodes = [Node("a",12), Node("b",4),Node("c",-5)]

returns the 3index of the smallest node in the node list.

+2
source

Source: https://habr.com/ru/post/1686379/


All Articles