c - How does list joining algorithm work? -


i have found in wayland protocol source code following function.

void wl_list_insert_list(struct wl_list *list, struct wl_list *other) {      if (wl_list_empty(other))          return;      other->next->prev = list;      other->prev->next = list->next;      list->next->prev = other->prev;      list->next = other->next;  } 

which operates on list has links so:

struct wl_list {     struct wl_list *prev;     struct wl_list *next; }; 

it doubly linked list other.

however not understand function @ all. me looks link 'other' lost both lists, , *list , *list->next links cross on other list.

also: not circular list. head , tail links point themselves.[edit] bad, in fact circular list. makes sense way.

could me understand how algorithm works. alot.

i drew pictures, stared @ them in confusion until realized magic. list , other not nodes, list objects. yes, other removed "it's list of nodes" because want add nodes of list other list list. after function ends, other removed, , circularly linked nodes linked list's nodes. enter image description here


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -