In the following example, key 4,5,6 should be on right, but it show on left
{ key: 0, n: "Father", s: "M", ux: 1},
{ key: 1, n: "Mother", s: "F", vir: 0},
{ key: 2, n: "Son", s: "M", m: 0, f: 1},
{ key: 3, n: "Son", s: "M", m: 0, f: 1},
{ key: 4, n: "youngest son", s: "M", m: 1, f: 0, ux: 5},
{ key: 5, n: "and his wife", s: "F", vir: 4},
{ key: 6, n: "their child", s: "M", m: 5, f: 4}
Second example, oldest son should be on left
{ key: 0, n: "Father", s: "M", ux: 1},
{ key: 1, n: "Mother", s: "F", vir: 0},
{ key: 2, n: "oldest Son", s: "M", m: 0, f: 1, ux: 3},
{ key: 3, n: "and his wife", s: "F", vir: 2},
{ key: 4, n: "Son", s: "M", m: 1, f: 0}
How to solve this order problem?