当前位置:首页 > 未命名 > 正文

链表算法的实现-尾插法插入节点

//尾插法
bool ListInsert_back(LinkList*& L, LinkNode* node)
{
	LinkNode* last = NULL;

	if(!L || !node) return false;

	//找到最后一个节点
	last = L;
	while (last->next) last = last->next;

	//新的节点链接到尾部
	node->next = NULL;
	last->next = node;
	return true;
}

f5edec818d28cfde419e1ada2cf1d4a4.jpg

last = L;
	while (last->next) last = last->next;


0de559369d7ddbcf4b40f08792a07f5b.jpg

	node->next = NULL;
	last->next = node;

75aa6b36ceffbee098afec434c5d8c41.jpg

更新时间 2024-11-23