Tree Serialize/Deserialize

Run Settings
LanguageJavascript
Language Version
Run Command
class LinkedList { constructor(node = null, next = null) { this.node = node; this.next = next; } } const test = new LinkedList("root"); console.log(test.node, deserializeStringToList(serializeList(test)).node); function serializeList(list) { let newList = list; const strArr = []; if (newList.node) strArr.push(newList.node); while(newList.next) { newList = newList.next; strArr.push(newList.node); } return strArr.join(','); } function deserializeStringToList(listString) { const listArray = listString.split(','); const listLength = listArray.length; const linkedListArray = new Array(listLength + 1); linkedListArray[listLength] = null; for (let x = listLength - 1; x >= 0; x--) { const node = listArray[x] || null; linkedListArray[x] = { node, next: linkedListArray[x+1] || null }; } return linkedListArray[0]; }
Editor Settings
Theme
Key bindings
Full width
Lines