Clarification on pop() and shift() methods
rthangam opened this issue · 2 comments
Just wanted to clarify if pop() and shift() methods need to remove the node as well ? I see only either next or prev reference is changed ? If we need to remove the node i guess both needs to be removed ?
Changing the reference let's the garbage collector delete the element.
Thanks. But when i tried with the following code on chrome console it didn't deleted the element.
var linkedList = new LinkedList();
linkedList.push({
name: 'John',
birthyear: 1981
});
linkedList.push({
name: 'Pavlo',
birthyear: 2000
});
linkedList.push({
name: 'Garry',
birthyear: 1989
});
linkedList.push({
name: 'Derek',
birthyear: 1990
});
linkedList.push({
name: 'Ivan',
birthyear: 1966
});
function printList(node){
console.log(node.data.name);
}
linkedList.inorder(printList);
VM919:2 John
VM919:2 Pavlo
VM919:2 Garry
VM919:2 Derek
VM919:2 Ivan
linkedList.pop()
exports.Node {data: {…}, next: null, prev: e…s.Node}
linkedList.inorder(printList);
VM919:2 John
VM919:2 Pavlo
VM919:2 Garry
VM919:2 Derek
VM919:2 Ivan
linkedList.pop()
exports.Node {data: {…}, next: null, prev: e…s.Node}
linkedList.inorder(printList);
VM919:2 John
VM919:2 Pavlo
VM919:2 Garry
VM919:2 Derek
VM919:2 Ivan
Is there anything wrong in my test code or Chrome console does something different ?