C 双向链表
来源:互联网 发布:获取东方财富k线数据 编辑:程序博客网 时间:2024/05/16 00:50
头文件(.h)
#pragma oncetypedef struct _NODES{ int count; char name[8]; struct _NODES* prev; struct _NODES* next;}NODES;
源文件(.c)
#include "LinkList.h"#include <stdlib.h>#include <string.h>NODES* lists = NULL;//添加到链表最后int _inserts(const char* name, int count){ NODES* node = (NODES*)malloc(sizeof(NODES)); node->count = count; strcpy(node->name,name); node->next = NULL; node->prev = NULL; if (lists==NULL) { lists = node; return 1; } for (NODES* p = lists; ; p=p->next) { if (p->next==NULL) { p->next = node; node->prev = p; return 1; } } return 0;}//根据count的大小插入数据int _inserts2(const char* name, int count){ NODES* node = (NODES*)malloc(sizeof(NODES)); node->count = count; strcpy(node->name, name); node->next = NULL; node->prev = NULL; if (lists == NULL) { lists = node; return 1; } if (count < lists->count) { node->next = lists; lists->prev = node; lists = node; return 1; } if (count > lists->count && lists->next==NULL) { lists->next = node; node->prev = lists; return 1; } if (count > lists->count && lists->next != NULL && count < lists->next->count) { node->next = lists->next; lists->next->prev = node; lists->next = node; node->prev = lists; return 1; } for (NODES* p = lists->next; p != NULL; p = p->next) { if (p->next==NULL) { p->next = node; node->prev = p; return 1; } if (count > p->count && count < p->next->count) { node->next = p->next; p->next->prev = node; node->prev = p; p->next = node; return 1; } } free(node); return 0;}//删除某节点(name)int _removes(const char* name){ for (NODES* p = lists; p !=NULL; p=p->next) { if (0==strcmp(p->name,name)) { if (p==lists) { lists = p->next; p->next->prev = NULL; free(p); return 1; } if (p->next==NULL) { p->prev->next = NULL; free(p); return 1; } p->prev->next = p->next; p->next->prev = p->prev; free(p); return 1; } } return 0;}//修改某节点信息int _modifys(int count, const char* NewName){ NODES* p = lists; int i = 0; while (p != NULL) { if (p->count==count) { memset(p->name, 0x00, sizeof(p->name)); strcpy(p->name, NewName); i++; } p = p->next; } return i;}
阅读全文
0 0
- 双向链表c
- C双向链表
- 【C++】双向链表
- 【C++】双向链表
- C 双向链表
- 双向链表C语言
- 数据结构(C#)--双向链表
- List-c双向链表
- [C++]双向链表操作
- 双向链表(C++)
- 双向链表-C语言版
- 双向链表-C语言版
- 【C++】 双向链表.cpp
- c的双向链表
- C语言双向链表
- C/C++/JAVA 双向链表实现
- 双向链表-C/C++-多项式操作
- C语言实现双向链表删除、插入、双向输出
- OpenCV-Python-Tutorial[1]
- 插入排序
- OpenCV-Python-学习笔记的目录
- 2017/11/6~2017/11/12学习Java总结
- mybatis传递多个参数
- C 双向链表
- 从来没做过管理
- http协议版本介绍
- 【51nod】1106 质数检测
- QT的TabWidget之TabBar大小修改
- 判断浏览器版本,当浏览器版本过低时提示升级浏览器,不显示原来页面内容
- VS 编译出错之文件编码
- 证书pfx转pem格式
- class sklearn.linear_model的简单应用,直接贴代码