📄 list.c
字号:
/****************************************************************************** Copyright(C) 2005,2006 Frank ZHANG All Rights Reserved. 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. ****************************************************************************** If you want to distribute this software with modifications under any terms other than the GPL or distribute the software linked with proprietary applications that are not distributed in full compliance with the GNU Public License, a Commercial License is needed. Commercial licensing and support of this software are available at a fee. For more information, See http://www.openmgcp.org ******************************************************************************//****************************************************************************** Copyright(C) 2005,2006 Frank ZHANG All Rights Reserved. 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., 675 Mass Ave, Cambridge, MA 02139, USA. ****************************************************************************** If you want to distribute this software with modifications under any terms other than the GPL or distribute the software linked with proprietary applications that are not distributed in full compliance with the GNU Public License, a Commercial License is needed. Commercial licensing and support of this software are available at a fee. For more information, See http://www.openmgcp.org ******************************************************************************//******************************************************************************* Authors : Frank ZHANG* Description : *** Date of creation : 04/03/2005*** History :* 2005/04/03 Frank ZHANG : - Creation******************************************************************************/#include <stdlib.h>#include "list.h"#include "debg.h"/*************************************************************************** * Function : SListInit * * Description : Initialize single-linked list * * Input parameters : pList - pointer to single-linked list * * Output parameters : pList - initialized list * * Return value : None * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/void SListInit (TSList* pList){ if (pList) { pList->count = 0; pList->cur = NULL; pList->pre = NULL; pList->head = NULL; pList->tail = NULL; }}/*************************************************************************** * Function : SListReset * * Description : Reset the current pointer in single-linked list to be * the header node pointer and the previous pointer to be * NULL; * * Input parameters : pList - pointer to single-linked list * * Output parameters : pList - current pointer is same as header pointer * * Return value : None * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/void SListReset(TSList* pList){ if (pList) { pList->pre = NULL; pList->cur = pList->head; }}/*************************************************************************** * Function : SListNextNode * * Description : Return the next node pointer to the current pointer * * Input parameters : pList - pointer to single-linked list * * Output parameters : pList - current pointer pointer to the next node * * Return value : The next node pointer of current pointer * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/TSListNode* SListNextNode(TSList* pList){ TSListNode *pNode = NULL; if (pList && pList->cur) { pList->pre = pList->cur; pNode = pList->cur = pList->cur->next; } return pNode;}/*************************************************************************** * Function : SListGetCurData * * Description : Get the data pointer of current node * * Input parameters : pList - pointer to single-linked list * * Output parameters : None * * Return value : The pointer to current node's data * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/void* SListGetCurData(TSList* pList){ if (pList && pList->cur) return pList->cur->data; else return NULL;}/*************************************************************************** * Function : SListFreeAll * * Description : Free each node and its data in single-linked list * * Input parameters : pList - pointer to single-linked list * * Output parameters : pList - all nodes and their data are freed * * Return value : None * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/void SListFreeAll (TSList* pList){ if (pList) { TSListNode *p1; TSListNode *p2 = pList->head; while (p2) { p1 = p2; p2 = p1->next; free(p1->data); free (p1); } SListInit (pList); }}/*************************************************************************** * Function : SListDel * * Description : Delete all the nodes in single-linked list but don't * free the node data * * Input parameters : pList - pointer to single-linked list * * Output parameters : pList - all nodes are deleted * * Return value : None * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/void SListDel (TSList* pList){ if (pList) { TSListNode *p1; TSListNode *p2 = pList->head; while (p2) { p1 = p2; p2 = p1->next; free (p1); } SListInit (pList); }}/*************************************************************************** * Function : SListAppend * * Description : Insert a node into the head of single-linked list * * Input parameters : pList - pointer to single-linked list * pData - pointer to the data associated with the added * node * * Output parameters : pList - new node is added * * Return value : The pointer of the new added node * * Comments : * * History : * 2005/04/03 : Creation * * Date : April 03 2005, Frank ZHANG **************************************************************************/TSListNode* SListAdd (TSList* pList, void* pData){ TSListNode* pListNode = (TSListNode*)malloc(sizeof(TSListNode)); if (pListNode) { pListNode->data = pData; pListNode->next = pList->head; pList->head = pListNode; pList->count++; } return pListNode;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -