线性表链式存储_api函数实现

传智课程学习笔记。


代码,大概敲得,可能有小错误,

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "linklist.h"

typedef struct _tag_LinkList
{
	LinkListNode header;
	int length;
}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 ;
	}
	tList = ( TLinkList *)list;
	return this->length;
}



int LinkList_Insert( LinkList* list, LinkListNode* node, int pos)
{
	int ret = 0;
	LinkLitsNode *current = NULL;
	TLinkList *tList = NULL;
	if( list == NULL || node == NULL || pos<0)
	{
		ret = 0; 
		printf("func LinkList_inserterr:%d\n", ret );
		return ret;
	}
	tList = ( TLinkList *)list;
	current = &(tList->header);

	for( i=0; i<pos && current->next!=NULL; i++ )
	{
		current = current->next;
	}

	node->next = current->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 || node==NULL | pos<0)
	{
		ret = 0;
		printf("func err:%d\n", ret);
		return NULL;
	}
	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 ret = 0, i=0;
	LinkListNode* current = NULL;

	TLinkList *tList = NULL;

	if( list == NULL || pos<0)
	{
		ret = 0;
		printf("func linklist_insert9) 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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值