明年这样 明年这样
关注数: 8 粉丝数: 88 发帖数: 825 关注贴吧数: 21
【求助】大神来帮忙解答新手的一个问题吧,晕了好久了 var k; //赋值时的循环变量var i = 0; //用于队列queue的写入和读取var pivot; //基准var result = "";var low;var high;var templow;var temphigh;var transitA; //移动两个元素的位置参数var transitB;var a;var b;var left; //移动两个元素的过程参数var right;var step; //用于改变每次移动的距离var judge = 0; //用于判定元素移动的终止var array = new Array(); //用于记录比较的数var queue = new Array(); //队列,用于记录每次比较后需要交换位置的元素位置function assignment() {for(k=0;k<10;k++)array[k]=document.getElementById("text"+k).value;pivot = array[0];low = 0;high = array.length-1;quickSort(array,low,high);move();outPut();outPutQueue();}function outPutQueue() {for(k=0;k<100;k++) {if(typeof queue[k] != "undefined")result += queue[k] + " ";elsebreak;}document.getElementById("text").value = result;}function outPut() {for(k=0;k<10;k++)document.getElementById("txt" + k).value = array[k]}function quickSort(array,templow,temphigh) {low = templow; high = temphigh;pivot = array[low];if(low < high) {while(low < high) {while(Number(array[high])>=pivot && low<high)high--;array[low] = array[high];queue[i] = low;queue[i+1] = high;i += 2;//将low和high的值压进一个队列中while(Number(array[low])<=pivot && low<high)low++;array[high] = array[low];queue[i] = low;queue[i+1] = high;i += 2;//将low和high的值压进一个队列中}array[low] = pivot;quickSort(array,templow,low-1);quickSort(array,low+1,temphigh);}}function move(){step = 0;if(typeof queue[i] != "undefined") {transitA = queue.shift();//alert(transitA);transitB = queue.shift();//alert(transitB);moveReal();}}function moveReal(){console.trace();a = transitA;b = transitB;judge = (b - a)*100;step += 1;if(a < b) {if(step >= judge){document.getElementById("text" + a).setAttribute("id","temp");document.getElementById("text" + b).setAttribute("id","text" + a);document.getElementById("temp").setAttribute("id","text" + b);i += 2;move();}else {document.getElementById("text" + a).style.left = a * 100 + 50 + step;document.getElementById("text" + b).style.left = b * 100 + 50 - step;setTimeout("moveReal()",10);}}else {i += 2;move();}} 这段代码的作用是对10个数字快速排序,用一个队列将每次要交换的两个元素的位置记录下来,等到排序结束后将这些元素的位置进行交换,即一个快速排序的可视化过程,但是在assignment()中调用的几个函数只有move()函数没反应,别的正常运行,求解释
1 下一页