1.循环, 永远非空
头插入: head->next = head;
在x节点后面插入t节点 t->next = x->next, x->next = t;;
删除x后的节点; x->next = x->next->next;
遍历循环
t = x;
do
{
....
t = t->next;
} while( t != head);
测试是否只有一个元素; if( head->next = head )
2.头指针,尾节点为空
初始化: head = null;
在 x 节点后插入 t 节点
if( x == null ) {head = t; head->next = NULL }
else { t ->next = x -> next; x->next = t;}
删除x后的节点: t = x->next; x->next = t->next;
测试表是否为空 if(head == NULL)
有哑元头节点, 尾节点为空
初始化 head = malloc( sizieof * head); head->next = NULL;
有哑元头和尾节点.
双向链表的删除
假设要删除的是t
t->next->prev = t->prev;
t->prev->next = t->next;
在双向链表x中插入t
t->next = x->next;
x->next->prev = t;
x->next = t;
t->prev = x;