数组循环遍历和递归遍历
function fun1(arr) {
if (arr === null) return;
for (let i = 0; i < arr.length; i++) {
console.log(arr[i])
}
}
function fun2(arr, index) {
if (arr === null || arr.length <= index) return
console(arr[index])
fun2(arr, ++index)
}
链表循环遍历和递归遍历
function fun1(root) {
let temp = root;
while(true) {
if (temp !== null) {
console.log(temp)
} else {
break;
}
temp = temp.next
}
}
function fun2(root){
if (root === null) return;
console.log(root)
fun2(root.next)
}