数据结构 第三季(part 3)

//静态链表:用数组描述的链表叫静态链表 
//数组的每个下标都对应着一个data和一个cur,data用来存放数据元素,游标相当于链表中的next指针

//线性表的静态链表的存储结构
#define MAXSIZE 100
typedef struct{
	ElemType data;
	int cur;//游标,为0时表示无指向
}Component,StaticLinkList(MAXSIZE);

//将一维数组space中各分量链成一备用链表
//space[0].cur为头指针,"0"表示空指针

Status InitList(StaticLinkList space){//初始化静态链表
	int i;
	for(i=0;i ListLength(L) + 1)
		return ERROR;
	j = Malloc_SSL(L);//
	if( j ){
		L[j].data = e;
		for(l=1;lListLength(L))
		return ERROR;
	k = MAXSIZE - 1;
	for(j=1;j<=i-1;j++)
		k = L[k].cur;
	j = L[k].cur;
	L[k].cur = L[j].cur;
	Free_SLL(L,j);
	return OK;
}

void Free_SLL(StaticLinkList space,int k){
	space[k].cur =space[0].cur;
	space[0].cur = k;
}

int ListLength(StaticLinkList L){//返回静态链表的长度
	int j =0;
	int i = L[MAXSIZE-1].cur;
	while(i){
		i = L[i].cur;
		j++
	}
	return j;

}

你可能感兴趣的:(数据结构)