遍历多个链表
const list1 = {
'val':1,
'next':{
'val':2,
'next':{
'val':3,
'next':undefined
}
}
}
const list2 = {
'val':1,
'next':{
'val':2,
'next':{
'val':3,
'next':undefined
}
}
}
遍历多个链表
var ergodic = function(list1, list2) {
while(list1 || list2){
console.log('list1',list1)
console.log('list2',list2)
list1 && list1 =list1.next
list2 && list2 =list2.next
}
};
ergodic(list1,list2)
/*
list1 {val: 1, next: {…}}
list2 {val: 1, next: {…}}
list1 {val: 2, next: {…}}
list2 {val: 2, next: {…}}
list1 {val: 3, next: undefined}
list2 {val: 3, next: undefined}
*/