首页 > 其他 > 详细

Algorithms: 链表

时间:2014-04-09 16:14:56      阅读:521      评论:0      收藏:0      [点我收藏+]

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

/*-------------------------------------------------------------------------------------
 * 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




 

Algorithms: 链表,布布扣,bubuko.com

Algorithms: 链表

原文:http://blog.csdn.net/qqzwp/article/details/23250499

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!