AMPS:双向链表源码解读
本节在上节单向链表的基础上看看AMPS中对双向链表的实现,与单向链表相同,双向链表在软件中的使用也相对比较广泛,在后面要讲到的Hash表、定时器、内存管理等模块中都会见到以双向链表作为基本数据结构。其实,双向链表在实现上使用了很多单向链表的操作,仅在插入、删除结点时需要多操作几步,所以理解了单向链表,这块就比较好理解了。同样,AMPS提供了以下API对双向链表进行操作:AMPS_LinkList.h[cpp]#ifndef __HEADER_AMPS_LINKLIST_H__#define __HEADER_AMPS_LINKLIST_H__#ifdef __cplusplusextern "C"{#endif#include "AMPS_API.h"#include "AMPS_Defines.h"typedef struct _AMPSSList t_AMPSSList;typedef struct _AMPSDList t_AMPSDList;/*单向链表结构*/struct _AMPSSList{void* pvData;t_AMPSSList* poAMPSSListNext;t_AMPSSList* poAMPSSListPrev;};/*双向链表结构*/struct _AMPSDList{unsigned char uchCount; /*结点个数*/t_AMPSSList* poAMPSSListHead;};t_AMPSDList* DList_Init(t_AMPSDList** r_ppoDList);int DList_Concat(t_AMPSDList** r_ppoDListSrc, t_AMPSDList* r_poDListDst);t_AMPSSList* DList_Append(t_AMPSDList* list, void* r_pvData);t_AMPSSList* DList_Prepend(t_AMPSDList* r_poDList, void* r_pvData);void DList_PrependGivenNode(t_AMPSDList* r_poDList, void* r_pvData, t_AMPSSList* r_poSListNode);void DList_AppendGivenNode(t_AMPSDList* r_poDList, void* r_pvData, t_AMPSSList* r_poSListNode);t_AMPSSList* DList_Search(t_AMPSDList* r_poDList, AMPS_LListCompareLinkDataCallback r_pfAMPS_LListCompareCallback, void* r_pvData);t_AMPSSList* DList_Find (t_AMPSDList* r_poDList, t_AMPSSList* r_poSListNode);int DList_Remove(t_AMPSDList** r_ppoDList, t_AMPSSList* r_poSListNode, AMPS_LListRemoveLinkDataCallback r_pfAMPS_LListRemoveLinkDataCallback);int DList_Sort(t_AMPSDList** r_ppoDList, AMPS_LListCompareLinkDataCallback r_pfAMPS_LListCompareCallback);void DList_SwapNodesData(t_AMPSSList* r_poNodeOne, t_AMPSSList* r_poNodeTwo);int DList_RemoveFirstNode(t_AMPSDList** r_ppoDList, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);void DList_RemoveNthNode(t_AMPSDList** r_ppoDList, int r_nLocation, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);t_AMPSSList* DList_InsertAfter (t_AMPSDList* r_poDList, t_AMPSSList* r_poSListPositionNode, void* r_pvData);t_AMPSSList* DList_InsertBefore (t_AMPSDList* r_poDList, t_AMPSSList* r_poSListPositionNode, void* r_pvData);void DList_Free(t_AMPSDList** r_ppoDList, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);void DList_FreeEx(t_AMPSDList** r_ppoDList, AMPS_LListProcessCallback r_pfAMPS_LListProcessCallback, void* r_pvData);void DList_FreeNodes(t_AMPSDList** r_ppoDList, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);void DList_Traverse(t_AMPSDList* r_poDList, AMPS_LListProcessCallback r_fpDList_ProcessCallback, void* r_pvArg);int DList_RemoveWithOutFree(t_AMPSDList* r_poDList, t_AMPSSList* r_poSListNode);int SList_RemoveWithOutFree(t_AMPSSList** r_ppoAMPSSListHead, t_AMPSSList* r_poAMPSSListNode);void* DList_GetNthNode(t_AMPSDList* r_poAMPSDList, int r_nNodeLocation);int DList_Copy(t_AMPSDList* r_poAMPSDListSrc, t_AMPSDList* r_poAMPSDListDest, AMPS_LListDuplicate r_pfAMPS_LListDuplicate);int DList_RemoveFromData(t_AMPSDList* r_poDList, void* r_pvData, AMPS_LListRemoveLinkDataCallback r_pfAMPS_LListRemoveLinkDataCallback);#ifdef __cplusplus}#endif#endif /* __HEADER_AMPS_LINKLIST_H__ */#ifndef __HEADER_AMPS_LINKLIST_H__#define __HEADER_AMPS_LINKLIST_H__#ifdef __cplusplusextern "C"{#endif#include "AMPS_API.h"#include "AMPS_Defines.h"typedef struct _AMPSSList t_AMPSSList;typedef struct _AMPSDList t_AMPSDList;/*单向链表结构*/struct _AMPSSList{void* pvData;t_AMPSSList* poAMPSSListNext;t_AMPSSList* poAMPSSListPrev;};/*双向链表结构*/struct _AMPSDList{unsigned char uchCount; /*结点个数*/t_AMPSSList* poAMPSSListHead;};t_AMPSDList* DList_Init(t_AMPSDList** r_ppoDList);int DList_Concat(t_AMPSDList** r_ppoDListSrc, t_AMPSDList* r_poDListDst);t_AMPSSList* DList_Append(t_AMPSDList* list, void* r_pvData);t_AMPSSList* DList_Prepend(t_AMPSDList* r_poDList, void* r_pvData);void DList_PrependGivenNode(t_AMPSDList* r_poDList, void* r_pvData, t_AMPSSList* r_poSListNode);void DList_AppendGivenNode(t_AMPSDList* r_poDList, void* r_pvData, t_AMPSSList* r_poSListNode);t_AMPSSList* DList_Search(t_AMPSDList* r_poDList, AMPS_LListCompareLinkDataCallback r_pfAMPS_LListCompareCallback, void* r_pvData);t_AMPSSList* DList_Find (t_AMPSDList* r_poDList, t_AMPSSList* r_poSListNode);int DList_Remove(t_AMPSDList** r_ppoDList, t_AMPSSList* r_poSListNode, AMPS_LListRemoveLinkDataCallback r_pfAMPS_LListRemoveLinkDataCallback);int DList_Sort(t_AMPSDList** r_ppoDList, AMPS_LListCompareLinkDataCallback r_pfAMPS_LListCompareCallback);void DList_SwapNodesData(t_AMPSSList* r_poNodeOne, t_AMPSSList* r_poNodeTwo);int DList_RemoveFirstNode(t_AMPSDList** r_ppoDList, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);void DList_RemoveNthNode(t_AMPSDList** r_ppoDList, int r_nLocation, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);t_AMPSSList* DList_InsertAfter (t_AMPSDList* r_poDList, t_AMPSSList* r_poSListPositionNode, void* r_pvData);t_AMPSSList* DList_InsertBefore (t_AMPSDList* r_poDList, t_AMPSSList* r_poSListPositionNode, void* r_pvData);void DList_Free(t_AMPSDList** r_ppoDList, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);void DList_FreeEx(t_AMPSDList** r_ppoDList, AMPS_LListProcessCallback r_pfAMPS_LListProcessCallback, void* r_pvData);void DList_FreeNodes(t_AMPSDList** r_ppoDList, AMPS_LListRemoveLinkDataCallback AMPS_LListRemoveLinkDataCallback);void DList_Traverse(t_AMPSDList* r_poDList, AMPS_LListPr补充:软件开发 , C++ ,
上一个:CF 264A(向内的双向队列)
下一个:节约空间的筛素数方法
- 更多C/C++疑问解答:
- 关于c++的cout输出的问题。
- 在学校里学过C和C++,不过学的很一般,现在自学C#,会不会很难?
- 全国计算机二级C语言笔试题
- 已知某树有2个2度结点,3个3度结点,4个4度结点,问有几个叶子结点?
- c++数据结构内部排序问题,整数排序
- 2012九月计算机二级C语言全国题库,,急求急求
- 如果assert只有一个字符串作为参数,是什么意思呢?
- C语言中,哪些运算符具有左结合性,哪些具有右结合性,帮忙总结下,谢谢了!
- 为什么用结构体编写的程序输入是,0输不出来啊~~~
- 将IEEE—754的十六进制转化为十进制浮点类型,用C或C++都行,多谢各位大侠啊,非常感谢!
- 为什么这个程序求不出公式?
- 这个链表倒置的算法请大家分析下
- c语言函数库调用
- C语言unsigned int纠错
- C语言快排求解啊