Skip to content

链表操作的图是不是画错了 #118

Open
@xincmm

Description

@xincmm
image 正确的画法应该是: image

源码和注释:

const sharedQueue: SharedQueue<State> = (updateQueue: any).shared;
  const pending = sharedQueue.pending;
  if (pending === null) { // 若链表中没有元素,则创建单向环状链表,next指向它自己
     update.next = update;
   } else {
     // 有元素,现有队列(pending)指向的是链表的尾部update,
     // pending.next就是头部update,新update会放到现有队列的最后并首尾相连
     // 将新队列的尾部(新插入的update)的next指向队列的首部,实现首位相连
     update.next = pending.next; 
    // 现有队列的最后一个元素的next指向新来的update,实现把新update接到现有队列上
     pending.next = update;
   } 
  // 现有队列的指针总是指向最后一个update,可以通过最后一个寻找出整条链表
  sharedQueue.pending = update;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions