国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

單鏈表功能函數(shù)練習(xí)——按規(guī)定插入指定節(jié)點(diǎn)及刪除最小值節(jié)點(diǎn)(C語言)

這篇具有很好參考價(jià)值的文章主要介紹了單鏈表功能函數(shù)練習(xí)——按規(guī)定插入指定節(jié)點(diǎn)及刪除最小值節(jié)點(diǎn)(C語言)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

本文屬于數(shù)據(jù)結(jié)構(gòu)中,單鏈表練習(xí)的一部分。共設(shè)計(jì)了兩個(gè)功能函數(shù),詳細(xì)信息如下。

設(shè)計(jì)在指定值的位置處,插入指定數(shù)據(jù)的函數(shù)

* 函數(shù)名稱: LList_DestInsert

* 函數(shù)功能: 在指定值位置處,插入指定的數(shù)據(jù)data

* 函數(shù)參數(shù):

? LList_t *Head: 需要操作的鏈表頭節(jié)點(diǎn)

? DataType_t dest: 插入位置的值

? DataType_t data: 需要插入的指定的數(shù)據(jù)

* 返回結(jié)果: true or false

* 注意事項(xiàng): None

* 函數(shù)作者: ni456xinmie@163.com

* 創(chuàng)建日期: 2024/04/22

* 修改歷史:

* 函數(shù)版本: V1.0

bool LList_DestInsert(LList_t *Head, DataType_t dest, DataType_t data)
{
	// 1.創(chuàng)建新的結(jié)點(diǎn),并對(duì)新結(jié)點(diǎn)進(jìn)行初始化
	LList_t *New = LList_NewNode(data);
	if (NULL == New)
	{
		printf("can not insert new node\n");
		return false;
	}
	LList_t *tmp = Head;
	while (tmp->data != dest && tmp->next != NULL) // 2.移動(dòng)到指定位置節(jié)點(diǎn)
	{
		tmp = tmp->next;
	}
	if (NULL == tmp->next)
	{
		if (tmp->data == dest)
		{
			New->next = NULL; // 3.如果指定目標(biāo)值在末尾,且dest正好也在末尾,可進(jìn)行尾插操作
			tmp->next = New->next;
			return true;
		}
		else
		{
			printf("There is no dest\n"); // 4.如果未找到指定目標(biāo)值,則返回
			return false;
		}
	}
	New->next = tmp->next; // 5.如果指定目標(biāo)值在中間,則進(jìn)行插入操作。
	tmp->next = New->next;
	return true;
}

設(shè)計(jì)刪除單鏈表鐘最小值節(jié)點(diǎn)的函數(shù)

* 函數(shù)名稱: LList_DeleteMin

* 函數(shù)功能: 刪除單鏈表中的最小值節(jié)點(diǎn)

* 函數(shù)參數(shù):

* LList_t *Head: 需要操作的鏈表頭節(jié)點(diǎn)

* 返回結(jié)果: true or false

* 注意事項(xiàng): None

* 函數(shù)作者: ni456xinmie@163.com

* 創(chuàng)建日期: 2024/04/22

* 修改歷史:

* 函數(shù)版本: V1.0

···文章來源地址http://www.zghlxwxcb.cn/news/detail-855854.html

bool LList_DeleteMin(LList_t *Head)
{
	LList_t *tmp1 = Head->next;		// 用來遍歷
	LList_t *tmpFormer = Head;		// 用來存放目標(biāo)指針前一個(gè)節(jié)點(diǎn)
	LList_t *tmpDest = Head->next;	// 用來存放目標(biāo)指針
	DataType_t tmpMin = tmp1->data; // 用來存放最小值
	if (!tmp1)						// 如果是空表
	{
		printf("The list is NULL");
		return false;
	}
	if (!tmp1->next) // 只有一個(gè)元素,就刪掉
	{
		free(Head->next);
		Head = NULL;
		return true;
	}
	while (tmp1->next) // 兩個(gè)以上的元素,定位到最小元素
	{
		if (tmpMin > tmp1->next->data)
		{
			tmpMin = tmp1->next->data;
			tmpDest = tmp1->next;
			tmpFormer = tmp1;
		}
		tmp1 = tmp1->next;
	}
	tmpFormer->next = tmpDest->next; // 進(jìn)行刪除操作
	free(tmpDest);
	return true;
}

到了這里,關(guān)于單鏈表功能函數(shù)練習(xí)——按規(guī)定插入指定節(jié)點(diǎn)及刪除最小值節(jié)點(diǎn)(C語言)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包