Created
August 22, 2021 14:01
-
-
Save pavanesh2021/7fa25bf5f1182f4c5646ec0ea31a4b49 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/focapic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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