List data structure - circular list

On demand and as doubly-linked list, but here we do not set a precursor node, but the first single list of connected together to form a circular list .

In order to empty the list of non-empty list, like dealing with them, we usually set up a head node, of course, this is not necessary, but this is very convenient.

The main difference is actually a circular linked list and single linked list is that the determination condition cycle, turned out to be determined p-> next is empty, it is now p-> next node is not equal to the head, the loop is not finished.

Further processing of the list, we introduce the definition of tail pointer.

 

 We just need to do:

p = rearA-> next; // A list of nodes to retain the head (the first step)

rearA-> next = rearB-> next-> next; // this is a pointer to the first node of the list B (non-head node) assigned to rearA-> next (second step)

rearB-> next = p; // original node A linked list head is assigned to rearB-> next (third step)

free(p);

 Thus, list A and list B combined, and the cancellation of the first node A linked list (list A former head node memory is released).

 

Guess you like

Origin www.cnblogs.com/jiameng991010/p/11304824.html