javascript Bubble sort problems (probably very easy) -
<html> <script> var tal; var array = []; var element=parseifloat(); function bubblesort(a){ var swapped, len = a.length; if(len === 1) return; { swapped = false; for(var i=1;i<len;i++) { if(a[i-1] > a[i]) { var b = a[i]; a[i] = a[i-1]; a[i-1] = b; swapped = true; } } } while(swapped) } function insertnumber(){ var element=document.getelementbyid("element").value; insert (element,array); } function insert(element, array) { array.push(element); alert(array); bubblesort(array); alert(array); } </script> <body> <input type="button" value="mata in" onclick="insertnumber()" id="resultat"> tal<input type="number" id="element" autofocus> </body> </html>
this code dont know how working again, problem cant read numbers correctly, trying use "var element=parseifloat(); " doesnt seem work..
thanks :)
sure, var element=parseifloat();
meant var element=parsefloat();
, put between
var element=document.getelementbyid("element").value;
and
insert (element,array);
Comments
Post a Comment