Algorithms: 链表

        什么叫真正理解一种数据结构,那就是在敲代码时,完全不看书,靠记忆力,纸和笔推导,一步步调试无错为止。

/*-------------------------------------------------------------------------------------
 * Project: List.c
 * Name: zwp
 * Date: 2014/4
 *--------------------------------------------------------------------------------------*/


#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include "List.h"



/*
** Initialize 
*/
LIST Initialize(LIST H)
{

	H = (LIST)malloc(sizeof(LIST));
	if(H == NULL)
		printf("Out of space....\n");
	  
	H->data = 0;
  	H->next = NULL;

	return H;

}



/*
** Empty
*/
unsigned int Empty(LIST H)
{
	return (H == NULL) ? 1 : 0;
}



/*
** Insert 
*/
void Insert(ElementType num, LIST H)
{
	List* N = (List*)malloc(sizeof(List));
	
	if(Empty(H))
	{
		H->next = N;
	}
	else
	{
		N->data = num;
		N->next = H->next;
		H->next = N;
	}	

}


/*
** Delete
*/
void Delete(ElementType num, LIST H)
{
	if(Empty(H))
		printf("The List is Empty...\n");

	LIST P = H; 
	LIST X = NULL;
	while(P != NULL)
	{
		X = P;
		P = P->next;
		if(P->data == num)
			break;
		
	}
	LIST T = P;
	X->next = P->next;

	free(T);
}




/*
** Travse
*/
void Travse(LIST H)
{
	LIST P = H->next;
	while(P != NULL)
	{
		printf("%d \n", P->data);
		P = P->next;
	}

}

/*-------------------------------------------------------------------------------
 * Project: List.h
 * Name: zwp
 * Date: 2014.4
 *-------------------------------------------------------------------------------*/



#ifndef LIST_H_
#define LIST_H_





typedef int ElementType;

typedef struct Node
{
	ElementType data;
	Node* next;
}List;


typedef List* LIST;


/*
** Initialize 
*/
LIST Initialize(LIST H);


/*
** Insert 
*/
void Insert(ElementType num, LIST H);


/*
** Delete
*/
void Delete(ElementType num, LIST H);


/*
** Travse
*/
void Travse(LIST H);


/*
** Empty
*/
unsigned int Empty(LIST H);






#endif




 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值