typedef struct
{
void* ptr;
int value;
}DOUBLE_LINK_T;
DOUBLE_LINK_T* insert(DOUBLE_LINK_T* pHead,int value)
{
DOUBLE_LINK_T* pCur = NULL;
DOUBLE_LINK_T* pNext = NULL;
DOUBLE_LINK_T* pPrevious = NULL;
DOUBLE_LINK_T* pNode = NULL;
pNode = new DOUBLE_LINK_T;
pNode->value = value;
// empty double list
if( NULL == pHead )
{
pHead = pNode;
pHead->ptr = NULL;
}
else
{
//find the cur list node
pPrevious = NULL;
pNext = (DOUBLE_LINK_T*) (NULL^(unsigned int)pHead->ptr);
if( NULL == pNext )
{
pHead->ptr = (void*)( NULL^(unsigned int)pNode );
pNode->ptr = (void*)( (unsigned int)pHead^NULL );
}
else
{
pPrevious = pHead;
do
{
pCur = pNext;
pNext = (DOUBLE_LINK_T*) ( (unsigned int)pPrevious^(unsigned int)pCur->ptr );
if( NULL != pNext)
pPrevious = pCur;
}
while( NULL != pNext
双向链表 只使用一个指针
最新推荐文章于 2022-04-08 20:59:16 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)