1
var bloodList = function (name, parent = null) {8
var ThroneInheritance = function (kingName) {9
this.nameMap = new Map();10
this.nameMap.set(kingName, bloodList(kingName));12
this.deadList = new Set();16
* @param {string} parentName17
* @param {string} childName20
ThroneInheritance.prototype.birth = function (parentName, childName) {21
const parent = this.nameMap.get(parentName);22
const childId = bloodList(childName, parent);23
this.nameMap.set(childName, childId);24
parent.children.push(childId);28
* @param {string} name31
ThroneInheritance.prototype.death = function (name) {32
this.deadList.add(name);38
function updateList(list, nameId, deadList) {39
if (!deadList.has(nameId.name)) list.push(nameId.name);41
for (let child of nameId.children) {42
updateList(list, child, deadList);46
ThroneInheritance.prototype.getInheritanceOrder = function () {48
updateList(list, this.nameMap.get(this.king), this.deadList);