Created
July 10, 2019 08:26
-
-
Save matbesancon/4abefc6a298be3a6ae6dd4e8a9f2dc44 to your computer and use it in GitHub Desktop.
Sort vertices by reversed degree order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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