# Graph serialization is a form of graph serialization.

```
L ← Empty list where we put the sorted elements
Q ← Set of all nodes with no incoming edges
while Q is non-empty do
remove a node n from Q
insert n into L
for each node m with an edge e from n to m do
remove edge e from the graph
if m has no other incoming edges then
insert m into Q
if graph has edges then
output error message (graph has a cycle)
else
output message (proposed topologically sorted order: L)
```

Tags: sorting algorithm directed-graph graph-algorithm

Source: By Kieron as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0

##### Related code-snippets:

- How can I get the value of in a loop?
- Function for creating color wheels.
- How do you sort a dictionary by value?
- What is the most efficient code for 10000 prime numbers?
- How can we efficiently get sorted sums of a sorted list?
- "Sorting" colors by distinctiveness. Followup:
- What is the best way to calculate Big O?
- Find largest rectangle in cubic cm (middle rectangle problem)!
- Looking for algorithm that reverses the sprintf() function output?
- Making human readable representations of an integer. This implies that a number is infinite (i.e. infinite number) and that the values of integer are equal to the number of numbers.
- How do I design a calendar like Google calendar?
- How does one sort an array by its value?
- How can I sort my list in C#?
- How can I optimize search algorithms in C language?
- What are some effective ways to compare float and double comparisons?