【数据结构】(单链表)带头结点删除最小值元素

叁歲伎倆 2021-10-29 22:08 420阅读 0赞

算法思想:while 循环 找出最小节点的前驱节点 以及最小值节点 之后删除即可

  1. void Delete_Min(LNode *&head ){
  2. if(head ->next==NULL)
  3. return;
  4. LNode *pre=head ; //前驱结点
  5. LNode *current=head ->next; //游标指针
  6. LNode *min=head ->next; //默认最小值结点是第一个结点
  7. while(current->next!=NULL){
  8. if(current->next->data<min->data){
  9. pre=current;
  10. min=current->next;
  11. }
  12. current=current->next;
  13. }
  14. LNode *f=min;
  15. pre->next=min->next;
  16. free(f);
  17. }

发表评论

表情:
评论列表 (有 0 条评论,420人围观)

还没有评论,来说两句吧...

相关阅读