# VertexList ordering of a simple graph

Given a simple graph like

g=Graph[{b -> c, a -> b}]


I would like to have f[g] resulting in {a,b,c} but for instance VertexList[g] results {b,c,a} which's not wanted. Is there any simple way to do this?

-
perhaps you can be more specific on f[]? Or is it a Sort of the vertexes? – FredrikD Dec 2 '12 at 4:47
Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the FAQs! 3) When you see good Q&A, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign – Vitaliy Kaurov Dec 2 '12 at 5:47

If you have disordered graph

g = Graph[{b -> c, a -> b}]; VertexList[g]


{b, c, a}

Use sort to find the order

f[g_] := Graph[Sort[VertexList[g]], EdgeList[g]];
VertexList[f[g]]


{a, b, c}

If your graph is directed and acyclic, then you have a built in function to sort based on topological order:

TopologicalSort[g]
`

{a, b, c}

-
Sorry, forgot to say the input data only contains edges. And the vertex doesn't limited to letters or numbers, the goal is to fine vertex ordering based on edges. – jamtype7 Dec 2 '12 at 4:23
@jamtype7 See update. – Vitaliy Kaurov Dec 2 '12 at 5:20