鸽了好久 项目终于做完了 做最后的上线准备 ,也顺便完成栈的应用
直接上代码
function dec2bin(element) {
var res = new Stack();
var res2 = [];
for (let i = element; i > 0;) {
if (i % 2 == 0) {
res.push(0);
} else if (i % 2 == 1) {
res.push(1);
}
i=Math.floor(i/2)
}
console.log(res.size());
while(!res.isEmpty()){
res2.push(res.pop())
}
return res2;
}
let result = dec2bin(100);
console.log(result);//[ 1, 1, 0, 0, 1, 0, 0 ]