Skip to content

Instantly share code, notes, and snippets.

@matbesancon
Created July 10, 2019 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matbesancon/4abefc6a298be3a6ae6dd4e8a9f2dc44 to your computer and use it in GitHub Desktop.
Save matbesancon/4abefc6a298be3a6ae6dd4e8a9f2dc44 to your computer and use it in GitHub Desktop.
Sort vertices by reversed degree order
function sort_by_degree(g::LightGraphs.AbstractGraph)
vs = vertices(g)
degrees = (degree(g, v) for v in vs)
vertex_pairs = collect(zip(vs, degrees))
sort!(vertex_pairs, by = p -> p[2], rev = true)
end
julia> sort_by_degree(path_graph(5))
5-element Array{Tuple{Int64,Int64},1}:
(2, 2)
(3, 2)
(4, 2)
(1, 1)
(5, 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment