#pragma once
typedef int dldatatype;
typedef struct dlistnode dlistnode,*dnode;
void dlistinit(dnode* head);
//尾插
void dlistnodepushback(dnode *head,dldatatype data);
//頭插
void dlistnodepushfront(dnode *head,dldatatype data);
//尾刪
void dlistnodepopback (dnode *head);
//頭刪
void dlistnodepopfront (dnode *head);
//列印
void dlistprint(dnode* head);
//任意位置的插入
void dlistnodeinsert(dnode *pos,dldatatype data);
//任意位置的刪除
void dlistnodeemrse(dnode *pos);
//尋找節點,返回位址
dlistnode* dlsitfind(dnode *head ,dldatatype data );
//清空,銷毀
void dlistclear(dnode *head);
void dlistdostry(dnode *head);
#include #include "dlist.h"
#include #include #include //要取二級指標
void dlistinit(dnode* head)
(*head)->p_next = *head;
(*head)->p_pre = *head;
}dlistnode* buydlistnode(dldatatype data )
node->data = data;
node->p_next = null;
node->p_pre = null;
return node;
}//尾插
void dlistnodepushback(dnode* head,dldatatype data)
node->p_pre = (*head)->p_pre;
(*head)->p_pre->p_next = node;
node->p_next = *head;
(*head)->p_pre = node;
}//頭插
void dlistnodepushfront(dnode *head,dldatatype data)
node = buydlistnode (data);
node->p_next = (*head)->p_next;
node->p_pre = (*head);
(*head)->p_next = node;
node->p_next->p_pre = node;
}//尾刪
void dlistnodepopback (dnode *head)
if(node->p_next == (*head))
temp = node;
while(node!=(*head))
else }}
//頭刪
void dlistnodepopfront (dnode *head)
(*head)->p_next = node->p_next;
node->p_next->p_pre = (*head) ;
free(node);
node = null;
return ;
}void dlistnodeinsert(dnode *pos,dldatatype data)
node = buydlistnode (data);
(*pos)->p_next->p_pre = node;
node->p_next = (*pos)->p_next;
node->p_pre = (*pos);
(*pos)->p_next = node;
}//任意位置的刪除
void dlistnodeemrse(dnode *pos)
(*pos)->p_next->p_pre = (*pos)->p_pre;
(*pos)->p_pre->p_next = (*pos)->p_next;
free(*pos);
(*pos) = null;
}dlistnode* dlsitfind(dnode *head ,dldatatype data )
node = (*head)->p_next;
while(node != (*head))
else
} return null;
}void dlistclear(dnode *head)
node = (*head)->p_next;
//釋放節點中的每乙個元素
//節點中的頭節點不斷指向本節點的下乙個節點
//釋放本節點
while(node != (*head))
/*while(node != (*head)) */
(*head)->p_next = (*head);
(*head)->p_pre = (*head); }
void dlistdostry(dnode *head)
void dlistprint(dnode* head)
printf("null\n");
}void dlisttest ()
int main ()
帶頭雙向鍊錶
ifndef list h define list h include stdio.h include assert.h include malloc.h include string.h typedef int datatype typedef struct listnode list,plist...
帶頭雙向鍊錶介面的實現
帶頭雙向鍊錶 include include include typedef int datatype typedef struct listnodelistnode typedef struct twolisttwolist 初始化 void twolistinit twolist pt 銷毀 v...
雙向鍊錶的實現(帶頭傀儡節點)
有注釋 class listnode public listnode int val public class doublelinkedlist 頭插法 public void addfirst int data node.next this.dummyhead.next this.dummyhea...