單鏈表的刪除

//接上一篇
//單鏈表的刪除
node * del(node *head,int num)
{
  node*p1,*p2;
  p1 = head;
  while(num!=p1->data && p1->data!= NULL)
 { p2 = p1; p1 = p1->next; }
 if(num == p1->data) { if(p1 == head) { head = p1->next; free(p1); } else { p2->next = p1->next; free(p1); } else { printf("not found this number!"); } } return head;}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章