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

數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版)

這篇具有很好參考價(jià)值的文章主要介紹了數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

前言?

? ? ? ? 單鏈表作為順序表的一種,了解并且熟悉它的結(jié)構(gòu)對(duì)于我們學(xué)習(xí)更加復(fù)雜的數(shù)據(jù)結(jié)構(gòu)是有一定意義的。雖然單鏈表有一定的缺陷,但是單鏈表也有它存在的價(jià)值,?它也是作為其他數(shù)據(jù)結(jié)構(gòu)的一部分出現(xiàn)的,比如在圖,哈希表中。

目錄

1.鏈表節(jié)點(diǎn)的結(jié)構(gòu)

2.頭插頭刪

3.尾插尾刪

4.任意位置的插入和刪除

5.查找鏈表的值和修改鏈表節(jié)點(diǎn)的值

6.銷毀鏈表

7.測(cè)試代碼

8.全部代碼

9.總結(jié)?


1.鏈表節(jié)點(diǎn)的結(jié)構(gòu)

? ? ? ? 單鏈表有節(jié)點(diǎn)的值和節(jié)點(diǎn)的next指針組成,如圖:

數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版),數(shù)據(jù)結(jié)構(gòu),c語(yǔ)言,開發(fā)語(yǔ)言?

typedef int SListDatatype;
typedef struct SListNode
{
	SListDatatype _data;//存儲(chǔ)節(jié)點(diǎn)的數(shù)據(jù)
	struct SListNode* _next;
}SListNode;

2.頭插頭刪

? ? ? ? 頭插分為兩種情況,第一種是沒(méi)有節(jié)點(diǎn)的情況,第二種是?有節(jié)點(diǎn)的情況。如圖:

數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版),數(shù)據(jù)結(jié)構(gòu),c語(yǔ)言,開發(fā)語(yǔ)言

? ? ? ? ? ? ? ? 頭刪也分為兩種情況,如果只有一個(gè)節(jié)點(diǎn)的時(shí)候,直接刪除就行了,然后將頭結(jié)點(diǎn)置空。如果有多個(gè)節(jié)點(diǎn),需要先記錄頭結(jié)點(diǎn),然后再進(jìn)行刪除就可以了。數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版),數(shù)據(jù)結(jié)構(gòu),c語(yǔ)言,開發(fā)語(yǔ)言

void SListPushFront(SListNode** ppHead, SListDatatype data)//頭插
{
	SListNode* newNode = SlistBuyNode(data);//申請(qǐng)一個(gè)新的節(jié)點(diǎn)
	if (*ppHead == NULL)
	{
		//鏈表為空
		*ppHead = newNode;
		return;
	}
	newNode->_next = (*ppHead);
	*ppHead = newNode;//對(duì)頭結(jié)點(diǎn)進(jìn)行鏈接
}
void SListPopFront(SListNode** ppHead)//頭刪
{
	assert(*ppHead);//確保指針的有效性
	if ((*ppHead)->_next == NULL)
	{
		//鏈表只有一個(gè)節(jié)點(diǎn)
		free(*ppHead);
		*ppHead = NULL;
		return;
	}
	//刪除頭結(jié)點(diǎn),然后更新頭結(jié)點(diǎn)
	SListNode* newHead = (*ppHead)->_next;
	free(*ppHead);
	*ppHead = newHead;
	return;
}

3.尾插尾刪

? ? ? ? 尾插也分為鏈表為空和指針不為空的情況,如果鏈表為空,申請(qǐng)節(jié)點(diǎn),讓鏈表的頭結(jié)點(diǎn)指向申請(qǐng)的節(jié)點(diǎn),然后將這個(gè)節(jié)點(diǎn)的_next置空,如果鏈表不為空,首先需要找到尾結(jié)點(diǎn),然后將尾結(jié)點(diǎn)與這個(gè)節(jié)點(diǎn)鏈接起來(lái),再將這個(gè)新申請(qǐng)的節(jié)點(diǎn)的_next置空。如圖:

?數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版),數(shù)據(jù)結(jié)構(gòu),c語(yǔ)言,開發(fā)語(yǔ)言

? ? ? ? 尾刪也分為兩種情況:1只有一個(gè)節(jié)點(diǎn)和2存在多個(gè)節(jié)點(diǎn)

如果只有一個(gè)節(jié)點(diǎn),刪除以后需要將頭結(jié)點(diǎn)置空,防止出現(xiàn)野指針的問(wèn)題。

如果有多個(gè)節(jié)點(diǎn),刪除尾結(jié)點(diǎn)以后需要將新的尾結(jié)點(diǎn)置空。

如圖:數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版),數(shù)據(jù)結(jié)構(gòu),c語(yǔ)言,開發(fā)語(yǔ)言?

void SListPushBack(SListNode** ppHead, SListDatatype data)//尾插
{
	SListNode*newNode =  SlistBuyNode(data);//申請(qǐng)一個(gè)新的節(jié)點(diǎn)
	
	if (*ppHead == NULL)//鏈表為空
	{
		*ppHead = newNode;
		return;
	}
	if ((*ppHead)->_next == NULL)//鏈表只存在一個(gè)節(jié)點(diǎn)
	{
		(*ppHead)->_next = newNode;
		return;
	}
	SListNode* cur = *ppHead;
	while (cur->_next)//找到尾節(jié)點(diǎn)
	{
		cur = cur->_next;
	}
	cur->_next = newNode;//進(jìn)行鏈接
	return;
}
void SListPopBack(SListNode** ppHead)//尾刪
{
	assert(*ppHead);
	if (*ppHead == NULL)//鏈表為空不需要?jiǎng)h除
	{
		return;
	}
	if ((*ppHead)->_next == NULL)
	{
		free(*ppHead);//鏈表只有一個(gè)節(jié)點(diǎn)
		(*ppHead) = NULL;
		return;
	}
	SListNode* cur = *ppHead;
	SListNode* prev = NULL;

	while (cur->_next)//找到尾結(jié)點(diǎn)
	{
		prev = cur;//保存上一個(gè)節(jié)點(diǎn)
		cur = cur->_next;
	}
	free(cur);//釋放尾結(jié)點(diǎn)所在的空間
	prev->_next = NULL;//將上一個(gè)節(jié)點(diǎn)的_next置空
	return;

4.任意位置的插入和刪除

? ? ? ? 由于單鏈表結(jié)構(gòu)的限制,這里只實(shí)現(xiàn)了在pos位置之后的插入和刪除,如果刪除pos的后一個(gè)節(jié)點(diǎn)就需要確保pos的后一個(gè)節(jié)點(diǎn)是存在的,否則就會(huì)出現(xiàn)問(wèn)題。

void SListInsertAfter(SListNode*pos, SListDatatype data)//任意位置的插入,在pos之后插入
{
	assert(pos);//確保指針不為空
	SListNode* newNode = SlistBuyNode(data);
	SListNode* next = pos->_next;
	pos->_next = newNode;
	newNode->_next = next;
}
void SListErase(SListNode*pos)//任意位置的刪除,pox位置之后的刪除
{
	assert(pos);//確保節(jié)點(diǎn)的有效性
	//如果只有一個(gè)節(jié)點(diǎn)
	if (pos->_next )//pos節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn)存在
	{
		SListNode* next = pos->_next;
		SListNode* nextNext = next->_next;
		free(next);//刪除節(jié)點(diǎn),重新鏈接
		pos->_next = nextNext;
	}
}

5.查找鏈表的值和修改鏈表節(jié)點(diǎn)的值

? ? ? ? 遍歷鏈表就可以對(duì)鏈表中的數(shù)據(jù)進(jìn)行查找,找到查找的值,就可以對(duì)節(jié)點(diǎn)的值進(jìn)行修改。?

SListNode* SListFind(SListNode* pHead, SListDatatype data)//查找
{
	SListNode* cur = pHead;
	while (cur)
	{
		if (cur->_data == data)
			return cur;
		cur = cur->_next;//迭代向后走
	}
	return NULL;//找不到
}

?

void testSList()
{
	//查找和修改的測(cè)試
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListNode* node = SListFind(pHead, 5);//查找
	if (node)
	{
		//節(jié)點(diǎn)的數(shù)據(jù)
		node->_data = 50;
	}
	SListPrint(pHead);
}

6.銷毀鏈表

void SListDestory(SListNode** ppHead)//銷毀
{
	assert(*ppHead);
	//確保指針有效性
	SListNode* cur = *ppHead;
	while (cur)
	{
		SListNode* freeNode = cur;
		cur = cur->_next;
		free(freeNode);

	}
	*ppHead = NULL;
}

?

7.測(cè)試代碼

void testSListBack()
{
	//尾插尾刪的測(cè)試代碼
	SListNode* pHead = NULL;
	SListPushBack(&pHead, 1);
	SListPushBack(&pHead, 2);
	SListPushBack(&pHead, 3);
	SListPushBack(&pHead, 4);
	SListPushBack(&pHead, 5);
	SListPushBack(&pHead, 6);
	SListPrint(pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);


}
void testSListFront()
{
	//頭插頭刪的測(cè)試代碼
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
}
void testSList()
{
	//查找和修改的測(cè)試
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListNode* node = SListFind(pHead, 5);//查找
	if (node)
	{
		//節(jié)點(diǎn)的數(shù)據(jù)
		node->_data = 50;
	}
	SListPrint(pHead);
}
void TestSList1()
{
	//對(duì)在pos節(jié)點(diǎn)之后進(jìn)行插入和刪除的測(cè)試
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListNode* node = SListFind(pHead, 5);//查找
	if (node)
	{
		
		//插入節(jié)點(diǎn)
		SListInsertAfter(node, -2);
		SListPrint(pHead);

		SListErase(node);
		SListPrint(pHead);

	}
	SListDestory(&pHead);
}

8.全部代碼

//SList.h

#pragma once
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<assert.h>
typedef int SListDatatype;
typedef struct SListNode
{
	SListDatatype _data;//存儲(chǔ)節(jié)點(diǎn)的數(shù)據(jù)
	struct SListNode* _next;
}SListNode;
SListNode* SlistBuyNode(SListDatatype data);


void SListDestory(SListNode** ppHead);//銷毀
void SListPushBack(SListNode**ppHead,SListDatatype data);//尾插
void SListPopBack(SListNode** ppHead );//尾刪

void SListPushFront(SListNode** ppHead, SListDatatype data);//頭插
void SListPopFront(SListNode** ppHead);//頭刪

void SListInsertAfter(SListNode* pos, SListDatatype data);//任意位置的插入

void SListErase(SListNode*pos);//任意位置的刪除

SListNode* SListFind(SListNode*pHead, SListDatatype data);//查找
void SListPrint(SListNode* pHead);//顯示鏈表數(shù)據(jù)
//void SListDestory(SListNode** ppHead);//刪除鏈表

?//SList.c

#include"SList.h"

SListNode* SlistBuyNode(SListDatatype data)
{
	 SListNode*newNode = (SListNode*)malloc(sizeof(SListNode));
	 if (newNode == NULL)
	 {
		 //申請(qǐng)節(jié)點(diǎn)失敗
		 printf("申請(qǐng)節(jié)點(diǎn)失敗\n");
		 exit(-1);//暴力返回
	 }
	 newNode->_data = data;//給節(jié)點(diǎn)賦值
	 newNode->_next = NULL;

	 return newNode;
}

void SListDestory(SListNode** ppHead)//銷毀
{
	assert(*ppHead);
	//確保指針有效性
	SListNode* cur = *ppHead;
	while (cur)
	{
		SListNode* freeNode = cur;
		cur = cur->_next;
		free(freeNode);

	}
	*ppHead = NULL;
}
void SListPushBack(SListNode** ppHead, SListDatatype data)//尾插
{
	SListNode*newNode =  SlistBuyNode(data);//申請(qǐng)一個(gè)新的節(jié)點(diǎn)
	
	if (*ppHead == NULL)//鏈表為空
	{
		*ppHead = newNode;
		return;
	}
	if ((*ppHead)->_next == NULL)//鏈表只存在一個(gè)節(jié)點(diǎn)
	{
		(*ppHead)->_next = newNode;
		return;
	}
	SListNode* cur = *ppHead;
	while (cur->_next)//找到尾節(jié)點(diǎn)
	{
		cur = cur->_next;
	}
	cur->_next = newNode;//進(jìn)行鏈接
	return;
}
void SListPopBack(SListNode** ppHead)//尾刪
{
	assert(*ppHead);
	if (*ppHead == NULL)//鏈表為空不需要?jiǎng)h除
	{
		return;
	}
	if ((*ppHead)->_next == NULL)
	{
		free(*ppHead);//鏈表只有一個(gè)節(jié)點(diǎn)
		(*ppHead) = NULL;
		return;
	}
	SListNode* cur = *ppHead;
	SListNode* prev = NULL;

	while (cur->_next)//找到尾結(jié)點(diǎn)
	{
		prev = cur;//保存上一個(gè)節(jié)點(diǎn)
		cur = cur->_next;
	}
	free(cur);//釋放尾結(jié)點(diǎn)所在的空間
	prev->_next = NULL;//將上一個(gè)節(jié)點(diǎn)的_next置空
	return;
}
void SListPushFront(SListNode** ppHead, SListDatatype data)//頭插
{
	SListNode* newNode = SlistBuyNode(data);//申請(qǐng)一個(gè)新的節(jié)點(diǎn)
	if (*ppHead == NULL)
	{
		//鏈表為空
		*ppHead = newNode;
		return;
	}
	newNode->_next = (*ppHead);
	*ppHead = newNode;//對(duì)頭結(jié)點(diǎn)進(jìn)行鏈接
}
void SListPopFront(SListNode** ppHead)//頭刪
{
	assert(*ppHead);//確保指針的有效性
	if ((*ppHead)->_next == NULL)
	{
		//鏈表只有一個(gè)節(jié)點(diǎn)
		free(*ppHead);
		*ppHead = NULL;
		return;
	}
	//刪除頭結(jié)點(diǎn),然后更新頭結(jié)點(diǎn)
	SListNode* newHead = (*ppHead)->_next;
	free(*ppHead);
	*ppHead = newHead;
	return;
}
void SListInsertAfter(SListNode*pos, SListDatatype data)//任意位置的插入,在pos之后插入
{
	assert(pos);//確保指針不為空
	SListNode* newNode = SlistBuyNode(data);
	SListNode* next = pos->_next;
	pos->_next = newNode;
	newNode->_next = next;
}
void SListErase(SListNode*pos)//任意位置的刪除,pox位置之后的刪除
{
	assert(pos);//確保節(jié)點(diǎn)的有效性
	//如果只有一個(gè)節(jié)點(diǎn)
	if (pos->_next )//pos節(jié)點(diǎn)的下一個(gè)節(jié)點(diǎn)存在
	{
		SListNode* next = pos->_next;
		SListNode* nextNext = next->_next;
		free(next);//刪除節(jié)點(diǎn),重新鏈接
		pos->_next = nextNext;
	}
}

SListNode* SListFind(SListNode* pHead, SListDatatype data)//查找
{
	SListNode* cur = pHead;
	while (cur)
	{
		if (cur->_data == data)
			return cur;
		cur = cur->_next;//迭代向后走
	}
	return NULL;//找不到
}
void SListPrint(SListNode* pHead)//顯示鏈表數(shù)據(jù)
{
	assert(pHead);//確保指針的有效性
	SListNode* cur = pHead;
	while (cur)
	{
		printf("%d ", cur->_data);
		printf("->");
		cur = cur->_next;
	}
	printf("NULL\n");
}

//test.c

#include"SList.h"
void testSListBack()
{
	//尾插尾刪的測(cè)試代碼
	SListNode* pHead = NULL;
	SListPushBack(&pHead, 1);
	SListPushBack(&pHead, 2);
	SListPushBack(&pHead, 3);
	SListPushBack(&pHead, 4);
	SListPushBack(&pHead, 5);
	SListPushBack(&pHead, 6);
	SListPrint(pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);
	SListPopBack(&pHead);


}
void testSListFront()
{
	//頭插頭刪的測(cè)試代碼
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
	SListPopFront(&pHead);
}
void testSList()
{
	//查找和修改的測(cè)試
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListNode* node = SListFind(pHead, 5);//查找
	if (node)
	{
		//節(jié)點(diǎn)的數(shù)據(jù)
		node->_data = 50;
	}
	SListPrint(pHead);
}
void TestSList1()
{
	//對(duì)在pos節(jié)點(diǎn)之后進(jìn)行插入和刪除的測(cè)試
	SListNode* pHead = NULL;
	SListPushFront(&pHead, 1);
	SListPushFront(&pHead, 2);
	SListPushFront(&pHead, 3);
	SListPushFront(&pHead, 4);
	SListPushFront(&pHead, 5);
	SListPushFront(&pHead, 6);
	SListPrint(pHead);
	SListNode* node = SListFind(pHead, 5);//查找
	if (node)
	{
		
		//插入節(jié)點(diǎn)
		SListInsertAfter(node, -2);
		SListPrint(pHead);

		SListErase(node);
		SListPrint(pHead);

	}
	SListDestory(&pHead);
}
int main()
{
	TestSList1();
	return 0;
}

?

9.總結(jié)?

? ? ? ? 鏈表與順序表區(qū)別和聯(lián)系。順序表是在數(shù)組的基礎(chǔ)上實(shí)現(xiàn)增刪查改的。并且插入時(shí)可以動(dòng)態(tài)增長(zhǎng)。順序表的缺陷:可能存在空間的浪費(fèi),增容有一定的效率損失,中間或者頭部數(shù)據(jù)的刪除,時(shí)間復(fù)雜度是O(n),因?yàn)橐矂?dòng)數(shù)據(jù)。這些問(wèn)題都是由鏈表來(lái)解決的,但是鏈表也有自己的缺陷,不能隨機(jī)訪問(wèn),存在內(nèi)存碎片等問(wèn)題。?其實(shí)沒(méi)有哪一種數(shù)據(jù)結(jié)構(gòu)是完美的,它們都有各自的缺陷,實(shí)際中的使用都是相輔相成的。文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-644026.html

到了這里,關(guān)于數(shù)據(jù)結(jié)構(gòu)——單鏈表的實(shí)現(xiàn)(c語(yǔ)言版)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(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)文章

  • 【數(shù)據(jù)結(jié)構(gòu)】單鏈表的基本操作 (C語(yǔ)言版)

    【數(shù)據(jù)結(jié)構(gòu)】單鏈表的基本操作 (C語(yǔ)言版)

    目錄 一、單鏈表 1、單鏈表的定義: 2、單鏈表的優(yōu)缺點(diǎn): 二、單鏈表的基本操作算法(C語(yǔ)言) 1、宏定義 2、創(chuàng)建結(jié)構(gòu)體 3、初始化 4、插入 4、求長(zhǎng)度 5、清空 6、銷毀? 7、取值 8、查找 9、刪除 10、頭插法創(chuàng)建單鏈表 11、尾插法創(chuàng)建單鏈表 三、單鏈表的全部代碼(C語(yǔ)言)

    2024年01月22日
    瀏覽(93)
  • 【數(shù)據(jù)結(jié)構(gòu)】 循環(huán)單鏈表的基本操作 (C語(yǔ)言版)

    【數(shù)據(jù)結(jié)構(gòu)】 循環(huán)單鏈表的基本操作 (C語(yǔ)言版)

    目錄 一、循環(huán)單鏈表 1、循環(huán)單鏈表的定義: 2、循環(huán)單鏈表的優(yōu)缺點(diǎn): 二、循環(huán)單鏈表的基本操作算法(C語(yǔ)言)?? ?1、宏定義 ?2、創(chuàng)建結(jié)構(gòu)體 3、循環(huán)單鏈表的初始化? 4、循環(huán)單鏈表的插入 5、求單鏈表長(zhǎng)度 6、循環(huán)單鏈表的清空 7、循環(huán)單鏈表的銷毀 8、循環(huán)單鏈表的取

    2024年01月22日
    瀏覽(93)
  • 【(數(shù)據(jù)結(jié)構(gòu))— 單鏈表的實(shí)現(xiàn)】

    【(數(shù)據(jù)結(jié)構(gòu))— 單鏈表的實(shí)現(xiàn)】

    概念: 鏈表是?種 物理存儲(chǔ)結(jié)構(gòu)上非連續(xù)、 非順序的存儲(chǔ)結(jié)構(gòu),數(shù)據(jù)元素的 邏輯順序 是通過(guò)鏈表中的 指針鏈接 次序?qū)崿F(xiàn)的 。 鏈表的結(jié)構(gòu)跟???廂相似,淡季時(shí)?次的?廂會(huì)相應(yīng)減少,旺季時(shí)?次的?廂會(huì)額外增加?節(jié)。只需要將???的某節(jié)?廂去掉/加上,不會(huì)影響

    2024年02月08日
    瀏覽(102)
  • 【數(shù)據(jù)結(jié)構(gòu)】單鏈表的實(shí)現(xiàn)

    【數(shù)據(jù)結(jié)構(gòu)】單鏈表的實(shí)現(xiàn)

    ??個(gè)人主頁(yè):平凡的小蘇 ??學(xué)習(xí)格言:別人可以拷貝我的模式,但不能拷貝我不斷往前的激情 ??C語(yǔ)言專欄:https://blog.csdn.net/vhhhbb/category_12174730.html ??數(shù)據(jù)結(jié)構(gòu)專欄:https://blog.csdn.net/vhhhbb/category_12211053.html ? ? ? ? 家人們更新不易,你們的??點(diǎn)贊??和?關(guān)注?真的對(duì)我

    2023年04月09日
    瀏覽(93)
  • 【數(shù)據(jù)結(jié)構(gòu)—單鏈表的實(shí)現(xiàn)】

    【數(shù)據(jù)結(jié)構(gòu)—單鏈表的實(shí)現(xiàn)】

    提示:文章寫完后,目錄可以自動(dòng)生成,如何生成可參考右邊的幫助文檔 目錄 前言 1. 鏈表的概念及結(jié)構(gòu) 2. 單鏈表的實(shí)現(xiàn) 2.1單鏈表頭文件——功能函數(shù)的定義 2.2單鏈表源文件——功能函數(shù)的實(shí)現(xiàn) 2.3 單鏈表源文件——功能的測(cè)試 3.具體的理解操作圖 4. 鏈表的分類 總結(jié) 世上

    2024年02月05日
    瀏覽(93)
  • 【數(shù)據(jù)結(jié)構(gòu)】-- 單鏈表的實(shí)現(xiàn)

    【數(shù)據(jù)結(jié)構(gòu)】-- 單鏈表的實(shí)現(xiàn)

    在前面我們學(xué)習(xí)了順序表,順序表在數(shù)組的基礎(chǔ)上提供了很多現(xiàn)成的方法,方便了我們對(duì)數(shù)據(jù)的管理,但是我們也發(fā)現(xiàn)順序表有著許多不足: 在處理大型的數(shù)據(jù)時(shí),需要頻繁的增容且在中間刪除或插入數(shù)據(jù)時(shí)需要遍歷順序表,這些性質(zhì)導(dǎo)致了順序表的 效率較低 。這時(shí)我們就

    2024年04月27日
    瀏覽(111)
  • C語(yǔ)言簡(jiǎn)單的數(shù)據(jù)結(jié)構(gòu):?jiǎn)捂湵淼挠嘘P(guān)算法題(2)

    C語(yǔ)言簡(jiǎn)單的數(shù)據(jù)結(jié)構(gòu):?jiǎn)捂湵淼挠嘘P(guān)算法題(2)

    接著我們介紹后面的三道題,雖然代碼變多了但我們的思路更加通順了 題目鏈接:https://leetcode.cn/problems/merge-two-sorted-lists/ 創(chuàng)建新鏈表,遍歷原鏈表,將節(jié)點(diǎn)值小的進(jìn)行尾插到新鏈表中 這里要多次進(jìn)行對(duì)NULL的判斷,開始傳入列表,中間newHead的判斷,循環(huán)出來(lái)一個(gè)為NULL的判斷

    2024年04月15日
    瀏覽(92)
  • 【數(shù)據(jù)結(jié)構(gòu)】單鏈表的層層實(shí)現(xiàn)!! !

    【數(shù)據(jù)結(jié)構(gòu)】單鏈表的層層實(shí)現(xiàn)!! !

    關(guān)注小莊 頓頓解饞(●’?’●) 上篇回顧 我們上篇學(xué)習(xí)了本質(zhì)為數(shù)組的數(shù)據(jù)結(jié)構(gòu)—順序表,順序表支持下標(biāo)隨機(jī)訪問(wèn)而且高速緩存命中率高,然而可能造成空間的浪費(fèi),同時(shí)增加數(shù)據(jù)時(shí)多次移動(dòng)會(huì)造成效率低下,那有什么解決之法呢?這就得引入我們鏈表這種數(shù)據(jù)結(jié)構(gòu) 概念

    2024年03月12日
    瀏覽(1049)
  • 【數(shù)據(jù)結(jié)構(gòu)】單鏈表的簡(jiǎn)單實(shí)現(xiàn)

    【數(shù)據(jù)結(jié)構(gòu)】單鏈表的簡(jiǎn)單實(shí)現(xiàn)

    提示:文章寫完后,目錄可以自動(dòng)生成,如何生成可參考右邊的幫助文檔 單鏈表是一種鏈?zhǔn)酱嫒〉臄?shù)據(jù)結(jié)構(gòu),用一組地址任意的存儲(chǔ)單元存放線性表中的數(shù)據(jù)元素。鏈表中的數(shù)據(jù)是以結(jié)點(diǎn)來(lái)表示的,每個(gè)結(jié)點(diǎn)的構(gòu)成:元素(數(shù)據(jù)元素的映象) + 指針(指示后繼元素存儲(chǔ)位置),元

    2024年02月04日
    瀏覽(96)
  • 【數(shù)據(jù)結(jié)構(gòu)】實(shí)現(xiàn)單鏈表的增刪查

    【數(shù)據(jù)結(jié)構(gòu)】實(shí)現(xiàn)單鏈表的增刪查

    鏈表類和節(jié)點(diǎn)類的定義: 圖解: 從中間位置插入: 圖解:假定index=2 尾插: 刪除當(dāng)前線性表中索引為index的元素,返回刪除的元素值: 圖解: 刪除當(dāng)前線性表中第一個(gè)值為element的元素: 刪除當(dāng)前線性表中所有值為element的元素: 將當(dāng)前線性表中index位置的元素替換為eleme

    2024年02月14日
    瀏覽(917)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

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

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

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包