Enter a graph as an adjacency list, and we'll sort it for you.
Or, if you're feeling fancy, use DFS instead.
Warning: this site is not responsible for any graph-related trauma or existential dread.