91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小:
    文件類型: .gz
    金幣: 1
    下載: 0 次
    發(fā)布日期: 2023-09-08
  • 語言: 其他
  • 標簽: 源碼??

資源簡介

《系統(tǒng)程序員成長計劃》源碼

資源截圖

代碼片段和文件信息

/*
?*?File:????dlist.c
?*?Author:??Li?XianJing?
?*?Brief:???double?list?implementation.
?*
?*?Copyright?(c)?Li?XianJing
?*
?*?Licensed?under?the?Academic?Free?License?version?2.1
?*
?*?This?program?is?free?software;?you?can?redistribute?it?and/or?modify
?*?it?under?the?terms?of?the?GNU?General?Public?License?as?published?by
?*?the?Free?Software?Foundation;?either?version?2?of?the?License?or
?*?(at?your?option)?any?later?version.
?*
?*?This?program?is?distributed?in?the?hope?that?it?will?be?useful
?*?but?WITHOUT?ANY?WARRANTY;?without?even?the?implied?warranty?of
?*?MERCHANTABILITY?or?FITNESS?FOR?A?PARTICULAR?PURPOSE.??See?the
?*?GNU?General?Public?License?for?more?details.
?*
?*?You?should?have?received?a?copy?of?the?GNU?General?Public?License
?*?along?with?this?program;?if?not?write?to?the?Free?Software
?*?Foundation?Inc.?59?Temple?Place?Suite?330?Boston?MA??02111-1307??USA
?*/

/*
?*?History:
?*?================================================================
?*?2008-11-09?Li?XianJing??created
?*
?*/
#include?
#include?“dlist.h“

typedef?struct?_DListNode
{
struct?_DListNode*?prev;
struct?_DListNode*?next;

void*?data;
}DListNode;

struct?_DList
{
DListNode*?first;
};

static?DListNode*?dlist_node_create(void*?data)
{
DListNode*?node?=?malloc(sizeof(DListNode));

if(node?!=?NULL)
{
node->prev?=?NULL;
node->next?=?NULL;
node->data?=?data;
}

return?node;
}

static?void?dlist_node_destroy(DListNode*?node)
{
if(node?!=?NULL)
{
node->next?=?NULL;
node->prev?=?NULL;
free(node);
}

return;
}

DList*?dlist_create(void)
{
DList*?thiz?=?malloc(sizeof(DList));

if(thiz?!=?NULL)
{
thiz->first?=?NULL;
}

return?thiz;
}

static?DListNode*?dlist_get_node(DList*?thiz?size_t?index?int?fail_return_last)
{
DListNode*?iter?=?thiz->first;

while(iter?!=?NULL?&&?iter->next?!=?NULL?&&?index?>?0)
{
iter?=?iter->next;
index--;
}

if(!fail_return_last)
{
iter?=?index?>?0???NULL?:?iter;
}

return?iter;
}

DListRet?dlist_insert(DList*?thiz?size_t?index?void*?data)
{
DListNode*?node?=?NULL;
DListNode*?cursor?=?NULL;

if((node?=?dlist_node_create(data))?==?NULL)
{
return?DLIST_RET_OOM;?
}

if(thiz->first?==?NULL)
{
thiz->first?=?node;

return?DLIST_RET_OK;
}

cursor?=?dlist_get_node(thiz?index?1);

if(index? {
if(thiz->first?==?cursor)
{
thiz->first?=?node;
}
else
{
cursor->prev->next?=?node;
node->prev?=?cursor->prev;
}
node->next?=?cursor;
cursor->prev?=?node;
}
else
{
cursor->next?=?node;
node->prev?=?cursor;
}

return?DLIST_RET_OK;
}

DListRet?dlist_prepend(DList*?thiz?void*?data)
{
return?dlist_insert(thiz?0?data);
}

DListRet?dlist_append(DList*?thiz?void*?data)
{
return?dlist_insert(thiz?-1?data);
}

DListRet?dlist_delete(DList*?thiz?size_t?index)
{
DListNode*?cursor?=?dlist_get_node(thiz?index?0);

if(cursor?!=?NULL)
{
if(cursor?==?thiz->first)
{
thiz->first?=

評論

共有 條評論