我们现在拥有一个指向当前节点的指针(current),以及一个指向当前节点的link的二级指针(rootp)。
下面将用next代替link,root-point代替rootp。
注意这里的root_point并不是指向节点本身,而是指向节点中的link字段,这是简化的关键所在。
我们不再需要previous这个指针。
int insert_node_update(node** root_point, int insert_value)
{
node* current;
node* new_;
//让root_point指向头结点中的next字段
root_point=&((*root_point)->next);
//current指向第一个节点
current=*root_point;
//按序访问链表,找到一个其值大于或等于新值的节点
while ((current=*root_point)!=NULL&¤t->data<insert_value)
{
root_point = ¤t->next;
}
new_ = (node*)malloc(sizeof(Node));
if (NULL == new_)
return FALSE;
new_->data = insert_value;
new_->next = current;
*root_point = new_;
return TRUE;
}