线性表链式存储_api函数实现
2017-03-08 18:12
330 查看
传智课程学习笔记。
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "linklist.h"
typedef struct _tag_LinkList
{
int length;
LinkListNode header;
}TlinkList;
LinkList* LinkList_Create()
{
TLinkList* ret = NULL;
ret = (TLinkList *)malloc( sizeof(TLinkList));
memset( ret, 0, sizeof(TLinkList));
ret->length = 0;
ret->header.next = NULL;
return ret;
}
void LinkList_Destroy( LinkList* list)
{
if( list != NULL)
{
free( list);
list = NULL;
}
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 = NULL;
if( list == NULL )
{
return -1;
}
tList = (TlinkList *)list;
return tList->length;
}
int LinkList_Insert( LinkList* list, LinkListNode* node, int pos)
{
int ret = 0, i=0;
LinkListNode *current = NULL;
if( list == NULL || node == NULL || pos<0 )
{
ret = 0;
printf("func LinkList_Insert() err:%d\n", ret);
return ret;
}
tList = ( TLinkList *)list;
current = &( tList->header);
for( i=0; i<pos&¤t->next!=NULL; i++)
{
current = current->next;
}
node->next = currentt->next;
current->next = node;
tList->length++;
return 0;
}
LinkListNode* LinkList_Get( LinkList* list, int pos)
{
int ret = 0 ,i=0;
LinkListNode *current = NULL;
TLinkList *tList = NULL;
if( list == NULL || pos<0)
{
ret = 0;
printf("func linklist insert() err:%\n", ret);
}
tList = (TLinkList *)list;
current = &(tList->header);
for( i=0; i<pos&&( current->next!=NULL); i++)
{
current = current->next;
}
return current->next;
}
LinkListNode* LinkList_Delete( LinkList* list, int pos)
{
int i=0;
LinkListNode *current = NULL;
LinkListNode *ret = NULL;
TLinkList *tList = NULL;
if( list == NULL || pos<0)
{
printf("func LinkList_Insert() err:%d\n", ret);
return NULL;
}
tList = (TLinkList *)list;
current = &(tList->header);
for( i=0; i<pos&&(current->next!=NULL); i++)
{
current = current->next;
}
ret = current->next;
current->next = ret->next;
return ret;
}
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "linklist.h"
typedef struct _tag_LinkList
{
int length;
LinkListNode header;
}TlinkList;
LinkList* LinkList_Create()
{
TLinkList* ret = NULL;
ret = (TLinkList *)malloc( sizeof(TLinkList));
memset( ret, 0, sizeof(TLinkList));
ret->length = 0;
ret->header.next = NULL;
return ret;
}
void LinkList_Destroy( LinkList* list)
{
if( list != NULL)
{
free( list);
list = NULL;
}
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 = NULL;
if( list == NULL )
{
return -1;
}
tList = (TlinkList *)list;
return tList->length;
}
int LinkList_Insert( LinkList* list, LinkListNode* node, int pos)
{
int ret = 0, i=0;
LinkListNode *current = NULL;
if( list == NULL || node == NULL || pos<0 )
{
ret = 0;
printf("func LinkList_Insert() err:%d\n", ret);
return ret;
}
tList = ( TLinkList *)list;
current = &( tList->header);
for( i=0; i<pos&¤t->next!=NULL; i++)
{
current = current->next;
}
node->next = currentt->next;
current->next = node;
tList->length++;
return 0;
}
LinkListNode* LinkList_Get( LinkList* list, int pos)
{
int ret = 0 ,i=0;
LinkListNode *current = NULL;
TLinkList *tList = NULL;
if( list == NULL || pos<0)
{
ret = 0;
printf("func linklist insert() err:%\n", ret);
}
tList = (TLinkList *)list;
current = &(tList->header);
for( i=0; i<pos&&( current->next!=NULL); i++)
{
current = current->next;
}
return current->next;
}
LinkListNode* LinkList_Delete( LinkList* list, int pos)
{
int i=0;
LinkListNode *current = NULL;
LinkListNode *ret = NULL;
TLinkList *tList = NULL;
if( list == NULL || pos<0)
{
printf("func LinkList_Insert() err:%d\n", ret);
return NULL;
}
tList = (TLinkList *)list;
current = &(tList->header);
for( i=0; i<pos&&(current->next!=NULL); i++)
{
current = current->next;
}
ret = current->next;
current->next = ret->next;
return ret;
}
相关文章推荐
- 线性表链式存储_api函数实现
- 线性表的链式存储结构之单链表类的实现之补充_Java
- 线性表的链式存储结构之单链表结点类的实现_Java
- 线性表链式存储的实现
- 线性表链式存储-使用c语言实现
- 线性表链式存储的实现详解
- 线性结构的顺序存储和链式存储的实现代码(一)
- 线性表的链式存储C语言实现
- PHP实现线性表的链式存储
- 线性表的Java实现--链式存储(单向链表)
- 线性表链式存储(双向循环链表)及其14种操作的实现
- 队列的线性存储和链式存储实现
- 线性表的顺序存储和链式存储的实现(C)
- 线性表链式存储的实现详解
- 线性表的链式存储结构之单链表结点类的实现_Java
- 线性表的链式存储结构之单链表类的实现_Java
- 数据结构:线性表的链式存储(单向链表)--Java实现
- 数据结构:线性表的链式存储(双向链表)--Java实现
- 线性表链式存储(单循环链表)及其15种操作的实现
- 数据结构之线性表――链式存储结构之单链表(php代码实现)