Incorrect!
-
Explanation
+
Explanation
Light up Animation
Close
@@ -158,7 +159,7 @@
Tree type
How to use
1. Use the left/right buttons to add nodes and delete button to remove nodes.
2. Build a binary tree that meets the specifications of the prompt.
-
3. Click "check" to verify answer.
+
3. Click "Check" to verify answer.
4. Click "Light-up animation" to see a light up animation of traversal
5. Click "Share Tree" share your tree with someone else
Close
diff --git a/index.html b/index.html
index cabf79a..934d947 100644
--- a/index.html
+++ b/index.html
@@ -104,10 +104,10 @@
Generate random tree
Max number of levels
Tree type
diff --git a/js/bst.js b/js/bst.js
index ebcc877..fbd22a2 100644
--- a/js/bst.js
+++ b/js/bst.js
@@ -475,7 +475,7 @@ function reversearr(arr){
function genbst(){
// suppose u have an arr
//let arr = [1,7,9,15,20,23,32,45,55,62,64,75,88,99];
- let arr = genlist(document.getElementById('numnodes').value);
+ let arr = genlist(document.getElementById('numnodes').value-1);
console.log('arr before ',arr);
// arr = reversearr(arr);
@@ -876,7 +876,7 @@ function getrandtree(){
function addlevel75(root, level){
- if (level >= document.getElementById('numnodes').value-1){
+ if (level >= document.getElementById('numnodes').value-2){
return;
}
let newnode;
@@ -979,26 +979,29 @@ function forcedark(){
}
+// toggle the angle of the connectors
function toggleangle(override){
var r = document.querySelector(':root');
+ // see the elapsed time since toggle was last clicked
let endtime = new Date();
var timediff = endtime - lasttoggle;
lasttoggle = endtime;
+ // prevent a double click of this
if (timediff < 333 && !override){
- console.log('returned');
+ // console.log('returned');
return;
}
if (angle == 'cornered'){
- // make light
+ // make curved
angle = 'curved';
localStorage.setItem('btangle','curved');
document.getElementById('lines').textContent = "Lines: (Curved)";
r.style.setProperty('--br', '25px');
} else {
- // make dark
+ // make cornered
angle = 'cornered';
localStorage.setItem('btangle','cornered');
document.getElementById('lines').textContent = "Lines: (Cornered)";
@@ -1007,7 +1010,6 @@ function toggleangle(override){
}
-
function preorderwithnullpointers(node){
if (node == null){
return "NULL";
diff --git a/js/exercise.js b/js/exercise.js
index e0479e1..75fdf91 100644
--- a/js/exercise.js
+++ b/js/exercise.js
@@ -402,6 +402,7 @@ function toggletheme(override){
r.style.setProperty('--contrast', 'black');
r.style.setProperty('--main', '#0d6efd');
r.style.setProperty('--slight', 'rgb(220,220,220)');
+ r.style.setProperty('--bgslight', 'rgba(255,255,255,0.6);');
} else {
// make dark
theme = 'dark';
@@ -411,6 +412,7 @@ function toggletheme(override){
r.style.setProperty('--contrast', 'white');
r.style.setProperty('--main', '#0d6efd');
r.style.setProperty('--slight', 'rgb(40, 40, 40)');
+ r.style.setProperty('--bgslight', 'rgba(0,0,0,0.6);');
}
}
@@ -510,7 +512,9 @@ function drawspaces(leftmargin,arr){
thedisp.innerHTML = ""; // reset
- if (0 < setarray.length && arr[0].toUpperCase() == setarray[0]){
+ if (spaceon <= 0){
+ clr = "var(--bg)";
+ } else if (0 < setarray.length && String(arr[0]).toUpperCase() == setarray[0]){
clr = "rgb(0,255,0)";
} else {
clr = "red";
@@ -523,7 +527,7 @@ function drawspaces(leftmargin,arr){
let clr;
if (spaceon <= i){
clr = "var(--bg)";
- } else if (i < setarray.length && arr[i].toUpperCase() == setarray[i]){
+ } else if (i < setarray.length && String(arr[i]).toUpperCase() == setarray[i]){
clr = "rgb(0,255,0)";
} else {
clr = "red";
@@ -837,9 +841,7 @@ function openscreen(){
let el = document.getElementById("screen");
el.style.display = "block";
el.style.opacity = 0.4;
-
- let res = document.getElementById("res");
- res.style.opacity = 0.4;
+
stayingup = true;
}
@@ -1152,6 +1154,32 @@ function verifyexercise(){
}
}
+function resettree(){
+ localStorage.removeItem('binarytreestorage');
+ root = new treenode('root',null,null);
+
+
+ leftbuttons = [];
+ delnodes = [];
+
+ // i know having a set capacity generally isnt good but im confident this will be more than enough
+ // could be increased but may impact performance if there are a bunch of not used really
+ nodearr = [root,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
+
+ disabled = false;
+
+ // intialx
+ x = 50;
+ y = 0;
+
+ rnzindex = 10;
+ stayingup = false;
+
+
+
+ redrawtree();
+}
+
@@ -1215,7 +1243,7 @@ redrawtree();
// update the count without interfereing with the stuff
(async () => {
- fetch((`https://skparabapi-1-x8164494.deta.app/increment?key=binarytree`))
+ fetch((`https://skparabapi-1-x8164494.deta.app/increment?key=exercise`))
.then(response => {
return response.json();
})
diff --git a/js/index.js b/js/index.js
index 6fb8105..121fe65 100644
--- a/js/index.js
+++ b/js/index.js
@@ -841,7 +841,7 @@ function getrandtree(){
function addlevel75(root, level){
- if (level >= document.getElementById('numnodes').value-1){
+ if (level >= document.getElementById('numnodes').value-2){
return;
}
let newnode;