Skip to content

Instantly share code, notes, and snippets.

@jimmont
Created March 5, 2020 03:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimmont/22424c3b288d10b829913eec3e91be81 to your computer and use it in GitHub Desktop.
Save jimmont/22424c3b288d10b829913eec3e91be81 to your computer and use it in GitHub Desktop.
LL
/*
add,remove,length, reverse
{value,next}
*/
class List{
constructor(){
}
}
class Node{
constructor(name, next=null){
this.name = String(name);
this.next = next;
}
}
class LL{
constructor(){
this.head = null;
}
add(name=''){
let node = this.head;
while(node && node.next){
node = node.next;
};
if(!node){
this.head = new Node(name);
}else{
node.next = new Node(name);
}
}
remove(name=''){
let node = this.head;
let parent;
while(node){
if(node.name === name){
}
node =
};
}
reverse(){
}
get length(){
}
toArray(){
const list = [];
let next = this;
do{
list.push(next);
next = next.next;
}while(next);
return list;
}
toString(){
return this.name;
//return `name: ${ this.name }, next: ${ this.next }`;
}
string(joiner=', '){
const list = this.toArray();
return list.join(joiner);
}
print(joiner){
return console.log(this.string(joiner));
}
}
var list = [];
console.log(list.print(''));
console.log(list.length);
console.log(list.reverse());
console.log(list.remove('I'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment