首页 > 解决方案 > 排序算法可视化

问题描述

我需要显示每个内部 for 循环的完成结果,但是在执行时,它直接显示最终结果。

const reframe = ()=>{
  ele = document.querySelectorAll(".element");
  ele.forEach((el,index) =>{
  el.style.height = `${arr[index]}px`;
 });
}

const selection_sort= ()=>{
    for( let j = 0 ; j< n-1 ; j++){
        for(let k = j+1 ; k<n ;k++){
            if(arr[j]>arr[k])
            {
                let temp = arr[j];
                arr[j]   = arr[k];
                arr[k]   =  temp;
                console.log(arr);
            }
            reframe();
        }

    }

}  

最终输出..我需要更改每个循环的可视化

标签: javascripthtmljquerycss

解决方案


推荐阅读