数据结构复习之路-线性表

来源:互联网 发布:vx什么软件 编辑:程序博客网 时间:2024/06/06 17:07

一,线性表是数据结构中最基础的内容,但它却占据着及其重要的地位。因为在后序的很多数据结构的操作都是建立在熟练掌握线性表的操作基础之上的。下面就开始复习线性表的内容吧。

1.线性表的定义。

线性表是指按顺序存储内容的数据结构。其物理实现的方式有两种,1)基于顺序存储的数组,2)基于链式存储的链表。

2.线性表的实现。

#define SIZE 50#define Type inttypedef struct{Type Data[SiZE];/*add some information about it */}List,*Plist;
typedef struct list{Type data;struct list* next;/*add some information about it */}List ,*PList;

3.线性表的基本操作(只说明基于链式存储的线性表)

1)初始化

PList init_List(PList Head){PList p,q,r;if(Head){printf("Error");return Head;}else{Head=(PList)malloc(sizeof(List));if(!Head){printf("Error");exit(1);}Head->data=0;Head->next=NULL;return Head;}}


2)添加结点
void add_Node(PList *Head,Type data){PList p=*Head,q;if(!*Head){printf("Error");return ;}while(p->next){p=p->next;}if(q=(PList)malloc(sizeof(List))){q->data=data;q->next=NULL;p->next=q;return;}else{printf("Error");return ;}}


3)删除结点
void del_NOde(PList *Head,Type data){PList p,q;p=*Head;q=p->next;if(!*Head){printf("Error");return ;}while(q){if(q->data==data){p->next=q->next;free(q);return ;}else{p=q;q=q->next;}}}


4.线性表的抽象相对简单,主要是考察C语言指针相关的操作。