嵌入式C语言数据结构之链表

链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。(百度百科)。

通俗来讲,链表的数据存储位置不确定,但是可以通过链表结构中的指针指向相应的数据,从而达到逻辑连续的目的。

链表适用于长度不确定的数据结构,插入或删除某个元素不需要调整整个数据结构。

链表不适用于频繁查找某个数据。

以下为源码,包含单链表,双链表和循环双链表

list.h

#ifndef __LIST_H__
#define __LIST_H__

#include "stm32f10x.h"
#include "stdlib.h"

#define MaxListLength 20

#define SingleList 1

#ifdef SingleList
	#define SingleListMode (1)
	typedef struct ListNode
	{
		uint32_t value;
		struct ListNode *pNext;
	}ListNode;
#endif

#ifdef DoubleList
	#define DoubleListMode (1)	
	typedef struct ListNode
	{
		uint32_t value;
		struct ListNode *pNext;
		struct ListNode *pLast;
	}ListNode;
#endif

#ifdef LoopList
	#define LoopListMode (1)
	typedef struct ListNode
	{
		uint32_t value;
		struct ListNode *pNext;
		struct ListNode *pLast;
	}ListNode;
#endif

typedef unsigned int ListState;

uint32_t List_GetListNodeCnt(ListNode *pHead);
	
ListState List_Init(ListNode * pHead,const uint32_t value);
ListState List_InsertNode(ListNode *pHead,const uint32_t node ,const uint32_t value);
ListState List_DeleteNode(ListNode *pHead,const uint32_t node);
ListState List_DeleteVal (ListNode *pHead,const uint32_t value);
ListNode* List_GetValueList (ListNode *pHead,const uint32_t value);

#endif

以下为list.c

#include "list.h"


static ListNode ListResult = {0};

/**
  * @name   List_Init.
  * @brief  Creat a list head.
  * @param  ListNode * pHead: Head of the list.
	    uint32_t   value: Value of th
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值