React循环链表结构js实现

const queue = { pending: null };

function dispatchAction(action, queue) {
  const update = { action: action, next: null };
  if (queue.pending == null) {
    update.next = update;
  } else {
    update.next = queue.pending.next;
    queue.pending.next = update;
  }
  queue.pending = update;
}

dispatchAction('update1', queue);
dispatchAction('update2', queue);

const first = queue.pending.next;
let update = first;
do {
  console.log(update);
  update = update.next;
} while (update != first);

  

上一篇:CHROME浏览器发送HTTP最大请求并发数限制


下一篇:NetSuite 为啥销货成本会变