Skip to content

Instantly share code, notes, and snippets.

@pavanesh2021
Created August 22, 2021 14:01
Show Gist options
  • Save pavanesh2021/7fa25bf5f1182f4c5646ec0ea31a4b49 to your computer and use it in GitHub Desktop.
Save pavanesh2021/7fa25bf5f1182f4c5646ec0ea31a4b49 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/focapic
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="box"></div>
<script id="jsbin-javascript">
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
insert(data) {
if (data < this.data && this.left) {
this.left.insert(data);
} else if (data < this.data) {
this.left = new Node(data);
}
if (data > this.data && this.right) {
this.right.insert(data);
} else if (data > this.data) {
this.right = new Node(data);
}
}
contains(data) {
if (this.data === data) {
return this;
}
if (data < this.data && this.left) {
return this.left.contains(data);
} else if (data > this.data && this.right) {
return this.right.contains(data);
} else {
return null;
}
}
}
var trp = new Node(2);
trp.insert(15);
trp.insert(7);
trp.insert(1);
console.log(trp);
</script>
<script id="jsbin-source-javascript" type="text/javascript">class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
insert(data) {
if (data < this.data && this.left) {
this.left.insert(data);
} else if (data < this.data) {
this.left = new Node(data);
}
if (data > this.data && this.right) {
this.right.insert(data);
} else if (data > this.data) {
this.right = new Node(data);
}
}
contains(data) {
if (this.data === data) {
return this;
}
if (data < this.data && this.left) {
return this.left.contains(data);
} else if (data > this.data && this.right) {
return this.right.contains(data);
} else {
return null;
}
}
}
var trp = new Node(2);
trp.insert(15);
trp.insert(7);
trp.insert(1);
console.log(trp);
</script></body>
</html>
class Node {
constructor(data) {
this.data = data;
this.left = null;
this.right = null;
}
insert(data) {
if (data < this.data && this.left) {
this.left.insert(data);
} else if (data < this.data) {
this.left = new Node(data);
}
if (data > this.data && this.right) {
this.right.insert(data);
} else if (data > this.data) {
this.right = new Node(data);
}
}
contains(data) {
if (this.data === data) {
return this;
}
if (data < this.data && this.left) {
return this.left.contains(data);
} else if (data > this.data && this.right) {
return this.right.contains(data);
} else {
return null;
}
}
}
var trp = new Node(2);
trp.insert(15);
trp.insert(7);
trp.insert(1);
console.log(trp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment