List单链表封装
来源:互联网 发布:天使与魔鬼 知乎 编辑:程序博客网 时间:2024/06/07 02:06
#include <stdlib.h>#include <string.h>#define MAX_PHONE_NUM 65#define CON_OK 1#define CON_FAIL 0typedef struct T_RelayCallItem{ char caller[MAX_PHONE_NUM]; char callee[MAX_PHONE_NUM]; int call_type; struct T_RelayCallItem *pNext;}tRelayCallItem;typedef struct T_RelayCallList{ int lens; tRelayCallItem *pHead; tRelayCallItem *pRear;}tRelayCallList;tRelayCallList g_RelayCallList;void InitRelayCallList(){ tRelayCallList *pList = &g_RelayCallList; pList->lens = 0; pList->pHead = NULL; pList->pRear = NULL;}tRelayCallItem *AddRelayCallIntoList(tRelayCallItem*pNew){ tRelayCallList *pList = &g_RelayCallList; tRelayCallItem *pRear = pList->pRear; if (pRear == NULL) { pList->pHead = pList->pRear = pNew; } else { pList->pRear->pNext = pNew; pList->pRear = pNew; } pList->lens++; return pNew;}tRelayCallList *DestroyRelayCallList(){ tRelayCallList *pList = &g_RelayCallList; tRelayCallItem *pHead = pList->pHead; while(pHead) { tRelayCallItem *pTmp = pHead->pNext; free(pHead); pHead = pTmp; } pList->pHead = pList->pRear = NULL; pList->lens = 0; return pList;}int DeleteRelayCallItemFromList(tRelayCallItem *pNew){ tRelayCallList *pList = &g_RelayCallList; tRelayCallItem *curr_node; tRelayCallItem *pre_node; if((pList == NULL) || (pNew == NULL)) { return CON_FAIL; } if(pList->pHead == pNew) { pList->pHead = pNew->pNext; if(pNew == pList->pRear) { pList->pRear = NULL; } free(pNew); pList->lens--; return CON_OK; } curr_node = pList->pHead; pre_node = curr_node; while(curr_node != NULL) { if(curr_node == pNew) { pre_node->pNext = curr_node->pNext; if(pNew == pList->pRear) { pList->pRear = pre_node; } free(pNew); pList->lens--; return CON_OK; } pre_node = curr_node; curr_node = curr_node->pNext; } return CON_FAIL;}int DeleteRelayCallItemByCallerCallee(char *caller, char *callee){ tRelayCallList *pList = &g_RelayCallList; tRelayCallItem *curr_node; tRelayCallItem *tmp_node; tRelayCallItem *pre_node; if((caller == NULL) || (callee == NULL)) { printf("Input pointer is NULL"); return CON_FAIL; } curr_node = pList->pHead; while(curr_node != NULL) { if((!strcmp(curr_node->caller,caller) && !strcmp(curr_node->callee,callee)) || (!strcmp(curr_node->caller,callee) && !strcmp(curr_node->callee,caller))) { tmp_node = curr_node->pNext; if (pList->pHead == curr_node) { pList->pHead = tmp_node; } if (pList->pRear == curr_node) { pList->pRear = NULL; } free(curr_node); pList->lens--; curr_node = tmp_node; tmp_node = tmp_node->pNext; } else { tmp_node = NULL; break; } } pre_node = curr_node; curr_node = curr_node->pNext; while(curr_node != NULL) { if((!strcmp(curr_node->caller,caller) && !strcmp(curr_node->callee,callee)) || (!strcmp(curr_node->caller,callee) && !strcmp(curr_node->callee,caller))) { pre_node->pNext = curr_node->pNext; if(curr_node == pList->pRear) { pList->pRear = pre_node; } free(curr_node); pList->lens--; curr_node = pre_node->pNext; } else { pre_node = curr_node; curr_node = curr_node->pNext; } } return CON_OK;}void PrintList(){ tRelayCallItem *item = g_RelayCallList.pHead;while (item != NULL){printf("-------caller:%s,callee:%s\n",item->caller,item->callee);item = item->pNext;}}int main(int argc, char* argv[]){ tRelayCallItem *item;int i;for (i = 0; i < 10 ; i ++){item = (tRelayCallItem *)malloc(sizeof(tRelayCallItem));memset(item,0,sizeof(tRelayCallItem));if (i%4 == 0){strcpy(item->caller,"35");strcpy(item->callee,"36");item->call_type = 1;}else if (i%4 == 1){strcpy(item->caller,"6051");strcpy(item->callee,"6052");item->call_type = 1;}else if (i%4 == 2){strcpy(item->caller,"36");strcpy(item->callee,"35");item->call_type = 2;}else{strcpy(item->caller,"6051");strcpy(item->callee,"6052");item->call_type = 2;}AddRelayCallIntoList(item);}PrintList();DeleteRelayCallItemByCallerCallee("35","36");PrintList();return 0;}
extern int g_dbg_level;extern FILE *g_log_fp;/* debug level */#define DBG_INFOR 0x01 // call information#define DBG_WARNING0x02 // paramters invalid, #define DBG_ERROR 0x04 // process error, leading to one call fails#define DBG_CRITICAL0x08 // process error, leading to voip process can't run exactly or exit/* debug macro */#define DBG(level, fmt, para...) \{ \time_t t = time(NULL); \struct tm *tmm = localtime(&t); \if(g_dbg_level & level) \printf("[%d-%02d-%02d %02d:%02d:%02d][%s][%s:%d]" fmt "\n",tmm->tm_year+1900,tmm->tm_mon+1,tmm->tm_mday,tmm->tm_hour,tmm->tm_min,tmm->tm_sec,__FUNCTION__,__FILE__,__LINE__,##para); \if((g_log_fp != NULL) && (level == DBG_CRITICAL))\fprintf(g_log_fp, "[%d-%02d-%02d %02d:%02d:%02d][%s][%s:%d]" fmt "\n",tmm->tm_year+1900,tmm->tm_mon+1,tmm->tm_mday,tmm->tm_hour,tmm->tm_min,tmm->tm_sec,__FUNCTION__,__FILE__,__LINE__,##para); \}
0 0
- List单链表封装
- List封装ResultSet
- JS封装LIST属性
- 字母封装的List排序
- spring mvc list 参数封装
- 一个仿Java类封装的std::list封装类
- Xfire封装对象和List型对象
- 将结果集封装到List中
- javascript封装的类似java List类
- Xfire封装对象和List型对象
- flex 封装mx:list 成两列显示组件
- UGUI(一)List列表的封装
- UGUI(1)List列表的封装
- Gson 将list封装成json
- springmvc封装list个数限制问题
- MyBatis查询结果封装成List
- 类对链表(list)的封装
- Redis操作List工具类封装,Java Redis List命令封装
- 网络爬虫开发技术实现
- 分享下我写评测的经验吧
- 子线程启用定时器
- HDU 1541 Stars
- Xcode:Undefined symbols for architecture i386:和"_OBJC_CLASS_$_xx", referenced from: error
- List单链表封装
- 在C和C++里const的用法异同总结
- ASP.NET MVC 中Ajax.ActionLink的用法
- MTK(3G)手机开发初学者必备资料(MMI)
- [译]Autoprefixer:一个以最好的方式处理浏览器前缀的后处理程序
- Struts1 访问 action 指定的某一个方法
- Remove Duplicates from Sorted Array II
- <游戏改变世界>摘录
- C# sqliet 读写 *.db 数据库