Created
May 11, 2014 12:27
-
-
Save kaka19ace/0028fd6aad8335dab91a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
copy from rtmpd 781 | |
*/ | |
#ifndef _LINKEDLIST_H | |
#define _LINKEDLIST_H | |
template<typename T> | |
struct LinkedListNode { | |
LinkedListNode<T> *pPrev; | |
LinkedListNode<T> *pNext; | |
T info; | |
}; | |
template<typename T> | |
LinkedListNode<T> *AddLinkedList(LinkedListNode<T> *pTo, T info, bool after) { | |
LinkedListNode<T> *pResult = new LinkedListNode<T>; | |
pResult->pNext = NULL; | |
pResult->pPrev = NULL; | |
pResult->info = info; | |
if (pTo != NULL) { | |
if (after) { | |
pTo->pNext = pResult; | |
pResult->pPrev = pTo; | |
} else { | |
pResult->pNext = pTo; | |
pTo->pPrev = pResult; | |
} | |
} | |
return pResult; | |
} | |
template<typename T> | |
LinkedListNode<T> *LastLinkedList(LinkedListNode<T> *pNode) { | |
while (pNode != NULL) { | |
if (pNode->pNext == NULL) | |
return pNode; | |
pNode = pNode->pNext; | |
} | |
return NULL; | |
} | |
template<typename T> | |
LinkedListNode<T> *RemoveLinkedList(LinkedListNode<T> *pNode) { | |
LinkedListNode<T> *pPrev = pNode->pPrev; | |
LinkedListNode<T> *pNext = pNode->pNext; | |
if (pPrev != NULL) | |
pPrev->pNext = pNext; | |
if (pNext != NULL) | |
pNext->pPrev = pPrev; | |
delete pNode; | |
if (pPrev != NULL) | |
return LastLinkedList<T > (pPrev); | |
return LastLinkedList<T > (pNext); | |
} | |
#endif /* _LINKEDLIST_H */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment