Create an order from several incomplete orders Here is the motivation and how it should behave, but I need a help how to implement it.

I have several (typically) incomplete orders given as ordered values, for ex.:
1. A, C, D
2. D, E
3. X, B
4. B, C
5. C, F
6. C, A

and the resulting order should be:
A, X, B, C, D, E, F or A, X, B, C, F, D, E or A, X, B, C, D, F, E

The idea behind it is sort the result based on first seen order. I will try explain it on the example in steps:
order A, C, D
D, E - D seen, so add E after D, so order A, C, D, E
X, B - no value seen yet, so we can not determine the order now, so create 2nd temporary order X, B
B, C - C already seen, so order A, B, C, D, E
and 2nd order can be merged via B, so A, X, B, C, D, E
C, F - C see, so order A, X, B, C, D, E, F
C, A - ignore, both values are part of already defined order (by first incomplete order A, C, D)

But what if an additional incomplete order F, D or F, E will be part (added to the end) of the input? The step-by-step mental algorithm will fail - F was already placed.

How can the idea be implemented, any idea?
I will answer the following question:


  Given a list of partial orders, how can we find a total order compatible with all of them, if any?


Form a directed graph on the ground set by putting an edge $a \to b$ if $a$ immediately precedes $b$ in one of the partial orders. If this graph contains any directed cycles, then there is no solution. Otherwise, we can find a solution by performing a topological sort.