fix: refactor parsing and also fix NaN
Fixes #10 Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
41c9c05ab2
commit
8c3de42f1f
2 changed files with 31 additions and 41 deletions
|
@ -12,37 +12,33 @@ let rRecorder = new Recorder(
|
||||||
let left = new AVLTree();
|
let left = new AVLTree();
|
||||||
let right = new WAVLTree();
|
let right = new WAVLTree();
|
||||||
|
|
||||||
left.recorder = lRecorder;
|
function operationCallback(lMethod, rMethod, id) {
|
||||||
right.recorder = rRecorder;
|
let number = document.getElementById(id).value;
|
||||||
|
let value = parseInt(number);
|
||||||
function insertCallback() {
|
if (number === "" || isNaN(value)) {
|
||||||
let number = document.getElementById("insertInput").value;
|
|
||||||
if (number === "") {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = parseInt(number);
|
lMethod(value);
|
||||||
|
rMethod(value);
|
||||||
left.insert(value);
|
document.getElementById(id).value = "";
|
||||||
right.insert(value);
|
|
||||||
|
|
||||||
document.getElementById("insertInput").value = "";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insertCallback() {
|
||||||
|
return operationCallback(
|
||||||
|
left.insert.bind(left),
|
||||||
|
right.insert.bind(right),
|
||||||
|
"insertInput"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function deleteCallback() {
|
function deleteCallback() {
|
||||||
let number = document.getElementById("deleteInput").value;
|
return operationCallback(
|
||||||
if (number === "") {
|
left.delete.bind(left),
|
||||||
return false;
|
right.delete.bind(right),
|
||||||
}
|
"deleteInput"
|
||||||
|
);
|
||||||
let value = parseInt(number);
|
|
||||||
|
|
||||||
left.delete(value);
|
|
||||||
right.delete(value);
|
|
||||||
|
|
||||||
document.getElementById("deleteInput").value = "";
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchTree(TreeType, side) {
|
function switchTree(TreeType, side) {
|
||||||
|
|
|
@ -7,30 +7,24 @@ let recorder = new Recorder(
|
||||||
let tree = new WAVLTree();
|
let tree = new WAVLTree();
|
||||||
tree.recorder = recorder;
|
tree.recorder = recorder;
|
||||||
|
|
||||||
function insertCallback() {
|
function operationCallback(method, id) {
|
||||||
let number = document.getElementById("insertInput").value;
|
let number = document.getElementById(id).value;
|
||||||
if (number === "") {
|
let value = parseInt(number);
|
||||||
|
if (number === "" || isNaN(value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = parseInt(number);
|
method(value);
|
||||||
tree.insert(value);
|
document.getElementById(id).value = "";
|
||||||
|
|
||||||
document.getElementById("insertInput").value = "";
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function insertCallback() {
|
||||||
|
return operationCallback(tree.insert.bind(tree), "insertInput");
|
||||||
|
}
|
||||||
|
|
||||||
function deleteCallback() {
|
function deleteCallback() {
|
||||||
let number = document.getElementById("deleteInput").value;
|
return operationCallback(tree.delete.bind(tree), "deleteInput");
|
||||||
if (number === "") {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
let value = parseInt(number);
|
|
||||||
tree.delete(value);
|
|
||||||
|
|
||||||
document.getElementById("deleteInput").value = "";
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function switchTree(TreeType) {
|
function switchTree(TreeType) {
|
||||||
|
|
Loading…
Reference in a new issue