插入函数最终版

在这里插入图片描述
我们现在拥有一个指向当前节点的指针(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&&current->data<insert_value)
	{
		root_point = &current->next;

	}
	new_ = (node*)malloc(sizeof(Node));
	if (NULL == new_)
		return FALSE;
	new_->data = insert_value;
	new_->next = current;
	*root_point = new_;
	return TRUE;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值