Skip to content

Commit

Permalink
Merge pull request wangzheng0822#268 from Devil0F/patch-3
Browse files Browse the repository at this point in the history
添加注释
  • Loading branch information
wangzheng0822 authored Mar 14, 2019
2 parents d97d22a + e3580e3 commit 2984168
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions c-cpp/06_linkedlist/Dlist/Dlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void dlist_init(stDlistHead *dlist) //链表初始化
return;
}

void dlist_destory(stDlistHead *dlist)
void dlist_destory(stDlistHead *dlist) //删除链表
{
stDlistNode *pNode = NULL;

Expand All @@ -40,7 +40,7 @@ int dlist_insert_head(stDlistHead *dlist,stDlistNode *pNode,int data) //插入
{
if(pNode == NULL) //当只传递一个数据时
{
pNode = (stDlistNode *)malloc(sizeof(stDlistNode)); //新建节点,为节点分配空间
pNode = (stDlistNode *)malloc(sizeof(stDlistNode)); //新建节点,为节点分配空间(malloc()可能需要#include<malloc.h>)
if (pNode == NULL)
{
return -1;
Expand All @@ -67,7 +67,7 @@ int dlist_insert_head(stDlistHead *dlist,stDlistNode *pNode,int data) //插入
return 0;
}

stDlistNode * dlist_remove_tail(stDlistHead *dlist) //删除尾部节点
stDlistNode * dlist_remove_tail(stDlistHead *dlist) //删除尾部节点,并返回删除节点
{
stDlistNode *pNode = NULL;

Expand All @@ -91,7 +91,7 @@ stDlistNode * dlist_remove_tail(stDlistHead *dlist) //删除尾部节点
return pNode;
}

void dlist_remove_node(stDlistHead * dlist,stDlistNode *pNode)
void dlist_remove_node(stDlistHead * dlist,stDlistNode *pNode) //删除指定节点
{
if ((dlist == NULL)||(pNode == NULL))
{
Expand Down Expand Up @@ -119,12 +119,12 @@ void dlist_remove_node(stDlistHead * dlist,stDlistNode *pNode)

if (dlist->size == 0)
{
memset(dlist,0,sizeof(stDlistHead));
memset(dlist,0,sizeof(stDlistHead)); //将dlist占用内存块的所有值置为0,也就是清空head,tail指针内容
}

return;
}
stDlistNode * dlist_search(stDlistHead * dlist,int data)
stDlistNode * dlist_search(stDlistHead * dlist,int data) //根据值搜索节点,并返回
{
stDlistNode *pNode = dlist->head;
while(pNode != NULL)
Expand Down Expand Up @@ -153,16 +153,16 @@ void dlist_dump(stDlistHead *dlist) //显示链表中的数据
}


void Lru_dlist(stDlistHead *dlist,int data)
void Lru_dlist(stDlistHead *dlist,int data) //LRU(最近最少使用)缓存淘汰算法
{
stDlistNode *pNode = NULL;

pNode = dlist_search(dlist,data);
if (pNode != NULL)
pNode = dlist_search(dlist,data);
if (pNode != NULL) //如果在链表中找到这个值,则删除储存这个值的节点,之后吧这个节点放在头部
{
dlist_remove_node(dlist,pNode);
}
else if(dlist->size >= 4)
else if(dlist->size >= 4) //没在链表中找到,且链表长度大于4,则从链表中删除尾部节点,将新数据放在头部
{
pNode = dlist_remove_tail(dlist);

Expand Down

0 comments on commit 2984168

Please sign in to comment.