• 當head != NULL時 • x → next = head; • tail → next = x;
head= x;
• x → next = head; • tail = x;
刪除動作 刪除節點於前端 tail → next = head → next; p = head; head =head → next ; free(p); head= x; 加入節點於尾端 tail → next = x; x → next = head; tail = x;
加入動作 void insert_node (struct node *ptr, struct node *head, struct node *tail) { struct node *prev; *this if (head = = NULL) { /*加入資料為第一筆 ptr -> next = ptr; head = ptr; tail = ptr; } this = head;
if (ptr ->key < this ->key) { /*加入前端 ptr -> next = this; head = ptr; tail -> next = head; } else { while (this -> next != head) { ptr = this; this = this ->next;