最近參考Linux實現的通用雙向鏈表時,因typeof並不是標准c規定的關鍵字,除GCC編譯器外其他編譯器未必支持typeof關鍵字,所以在使用上並不能想Linux所實現的鏈表哪樣靈活,它要求將連接器即鏈表結構作為用戶自定義結構體的第一個元素使用,話不多說,直接上代碼,內嵌詳細注釋。
IList.h
_I_LIST_H_2012_11_23_
typedef _IList * _IList * }IList, *
IList_Foreach(pList, pos) \
pos = pos = (pList)-> pos != pos = pos->
IList_Foreach_Salf(pList, temp, pos) \
pos = (pList)->_next, temp = pos-> pos != pos = temp, temp = pos->
pIList IList_Nth(pIList pList,
IList.c
#include <stdio.h>
#include
pList->_prev = pList->_next =
pNewLink->_prev = pLink-> pNewLink->_next = pNewLink->_prev->_next = pNewLink->_next->_prev =
IList_Insert(pList->
pLink->_prev->_next = pLink-> pLink->_next->_prev = pLink->
pList->_next != pList ? pList->
pList->_prev != pList ? pList->
pList->_next ==
count = pIList temp =
(pList->_next ==
count ++
pLink->_next != pList ? pLink->
pLink->_prev != pList ? pLink->
pIList IList_Nth(pIList pList, pIList pLink = count =
count ++ (count ==
pIList pTemp = index =
pTemp =
((pTemp != NULL) && (pTemp != index++ pTemp =
(pTemp == (-
}
IListTest.c
#include <stdio.h><stdlib.h><.h> ** main( argc, * i = num = count = = (argc > = atoi(argv[= (IList *)malloc( (! -, (i = ; i < num; i ++= malloc( (! -, ->_id = i + &temp->
=, temp->, &=, count, ((pStudent)link)->, ((pStudent)link)->
(