c链表
来源:互联网 发布:adaboost算法 编辑:程序博客网 时间:2024/06/05 07:12
include
include “stdlib.h”
include “string.h”
ifndef MYLINKLIST_H
define MYLINKLIST_H
//头文件
typedef void LinkList;
/*
typedef struct _tag_LinkListNode LinkListNode;
struct _tag_LinkListNode
{
LinkListNode* next;
};
*/
typedef struct _tag_LinkListNode
{
struct _tag_LinkListNode* next;
}LinkListNode;
LinkList* LinkList_Create();
void LinkList_Destroy(LinkList* list);
void LinkList_Clear(LinkList* list);
int LinkList_Length(LinkList* list);
int LinkList_Insert(LinkList* list, LinkListNode* node, int pos);
LinkListNode* LinkList_Get(LinkList* list, int pos);
LinkListNode* LinkList_Delete(LinkList* list, int pos);
endif
typedef struct _tag_LinkList
{
//这个句柄里面,需要保存所有节点信息。需要有一个起始点
//就是带头节点的链表。。。
LinkListNode header;
int length;
}TLinkList;
LinkList* LinkList_Create()
{
TLinkList ret = (TLinkList )malloc(sizeof(TLinkList));
if (ret == NULL)
{
return NULL;
}
//memset(ret, 0, sizeof(TLinkList));
ret->header.next = NULL;
ret->length = 0;
return ret;
}
void LinkList_Destroy(LinkList* list)
{
if (list == NULL)
{
return ;
}
free(list);
return ;
}
void LinkList_Clear(LinkList* list)
{
TLinkList *tList =NULL;if (list == NULL){ return ;}tList = (TLinkList *)list;tList->length = 0;tList->header.next = NULL;return ;
}
int LinkList_Length(LinkList* list)
{
TLinkList *tList = (TLinkList *)list;if (tList == NULL){ return -1;}return tList->length;
}
int LinkList_Insert(LinkList* list, LinkListNode* node, int pos)
{
int i = 0;
TLinkList *tList = NULL;LinkListNode *current = NULL;tList = (TLinkList *)list;//准备环境让辅助指针变量 指向链表头节点current = &tList->header;for (i=0; i<pos &&(current->next!=NULL); i++){ current = current->next;}//让node节点链接后续链表node->next = current->next ;//让前边的链表。链接nodecurrent->next = node;tList->length ++; return 0;
}
LinkListNode* LinkList_Get(LinkList* list, int pos)
{
int i = 0;TLinkList *tList = NULL;LinkListNode *current = NULL;LinkListNode *ret = NULL;tList = (TLinkList *)list;if (list == NULL || pos <0 ||pos>=tList->length){ return NULL;}//准备环境让辅助指针变量 指向链表头节点current = &tList->header;for (i=0; i<pos &&(current->next!=NULL); i++){ current = current->next;}ret = current->next;return ret;
}
LinkListNode* LinkList_Delete(LinkList* list, int pos)
{
int i = 0;
TLinkList *tList = NULL;LinkListNode *current = NULL;LinkListNode *ret = NULL;tList = (TLinkList *)list;if (list == NULL || pos <0 ||pos>=tList->length){ return NULL;}//准备环境让辅助指针变量 指向链表头节点current = &tList->header;for (i=0; i<pos &&(current->next!=NULL); i++){ current = current->next;}ret = current->next;//删除算法current->next =ret->next;tList->length--;return ret;
}
- C链表
- c 链表
- 链表(C#)
- C链表
- C 链表
- [C]链表
- C 链表
- 【C++】链表
- C 链表
- c链表
- C-链表
- c 链表
- C链表
- c链表
- 链表 c
- C++:链表
- C 链表
- C语言泛型初探----C链表
- javascript与node.js的区别
- 《Android源码设计模式解析与实战》读书笔记(十八)——代理模式
- 走出循环结构的几种方法:continue,break,goto,return
- 顺序表(静态)
- 程序员的自我修养
- c链表
- Delphi 接口编程之:接口委托
- Javascript事件机制
- GMIS 2017大会戴文渊演讲:构建AI商业大脑
- SpringMVC之RequestContextHolder分析
- git ssh 配置
- java接口简介
- 金属4.2开发之后总结
- java学习记录--ThreadLocal使用案例