?? com_list.c
字號:
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include "Com_List.h"
struct ComListItem_t* ComListCreate()
{
struct ComListItem_t* pHead;
pHead = (struct ComListItem_t*)malloc(sizeof(struct ComListItem_t));
if ( NULL == pHead )
{
return NULL;
}
pHead->pFront = pHead;
pHead->pNext = pHead;
return pHead;
}
int ComListInsert(struct ComListItem_t* pHead, void* pNode, int len )
{
struct ComListItem_t* pItem;
if ((NULL == pHead) || (NULL == pNode))
{
return 0;
}
pItem = (struct ComListItem_t*)malloc(len + sizeof(struct ComListItem_t));
if (NULL == pItem)
{
return 0;
}
memcpy(pItem->Data, pNode, len );
pItem->pFront = pHead->pFront;
pHead->pFront->pNext = pItem;
pHead->pFront = pItem;
pItem->pNext = pHead;
return 1;
}
int ComListSearch(struct ComListItem_t* pHead, void* pNode, int len, COMPAREFUNC pCompare)
{
struct ComListItem_t* pItem;
if ( (NULL == pHead) || (NULL == pNode) )
{
return 0;
}
if ( NULL == pCompare )
{
for (pItem = pHead->pNext; pItem != pHead; pItem = pItem->pNext)
{
if (!memcmp( (void*)pItem->Data, pNode, len))
{
return 1;
}
}
return 0;
}
else
{
for (pItem = pHead->pNext; pItem != pHead; pItem = pItem->pNext)
{
if (pCompare(pItem->Data, pNode))
{
return 1;
}
}
return 0;
}
}
int ComListDelete(struct ComListItem_t* pHead, void* pNode, int len, COMPAREFUNC pCompare)
{
struct ComListItem_t* pItem;
if ( (NULL == pHead) || (NULL == pNode) )
{
return 0;
}
if (len < sizeof(struct ComListItem_t))
{
return 0;
}
if ( NULL == pCompare )
{
for (pItem = pHead->pNext; pItem != pHead; pItem = pItem->pNext)
{
if (!memcmp( (void*)pItem->Data, pNode, len))
{
pItem->pFront->pNext = pItem->pNext;
pItem->pNext->pFront = pItem->pFront;
free(pItem);
return 1;
}
}
return 0;
}
else
{
for (pItem = pHead->pNext; pItem != pHead; pItem = pItem->pNext)
{
if (pCompare(pItem, pNode))
{
pItem->pFront->pNext = pItem->pNext;
pItem->pNext->pFront = pItem->pFront;
free(pItem);
return 1;
}
}
return 0;
}
}
int ComListErase(struct ComListItem_t* pHead)
{
struct ComListItem_t *pItem, *pNext;
if(NULL == pHead)
return 1;
pItem = pHead->pNext;
while(pItem != pHead)
{
pNext = pItem->pNext;
free(pItem);
pItem = pNext;
}
/* delete the head node */
free(pHead);
return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -