做互助盘网站,二次开发和一次开发哪个好,有没有厂家,本人承接网站建设方法1#xff1a;原链表删除元素 伪代码#xff1a; 首先判断头节点是否是待删除元素。#xff08;头节点和其他节点的删除方法不一样#xff09;
while(head ! null head-value target)
//如果链表为 1 1 1 1 1#xff0c;要删除元素1时用if就会失效
{h…方法1原链表删除元素 伪代码 首先判断头节点是否是待删除元素。头节点和其他节点的删除方法不一样
while(head ! null head-value target)
//如果链表为 1 1 1 1 1要删除元素1时用if就会失效
{head head-next;
}
cur head;
//为什么不是从head-next开始
//因为不方便删除链表节点如果指向head-next的话head会丢失不方便删除链表节点
while(cur ! null cur -next ! null)
{if(cur-next-value target){cur-next cur-next-next;}else{cur cur-next;}
}
return head;方法2虚拟头节点 增加一个虚拟头节点如果删除的是头节点那么直接删除就行。
伪代码
dumyhead new();//创建虚拟头节点
dumyhead-next head;
cur dumy-head;
while(cur-next ! null)
{if(cur-next-value target)cur-next cur-next-next;elsecur cur-next;
}
return dumyhead-next;