急需一个静态链表,请哪位帮忙做个静态链表?

来源:百度知道 编辑:UC知道 时间:2024/06/05 06:10:10
要求有插入与删除,分为两个函数,希望能尽可能的长一点.谢谢啦
怎么实现起来有错误?有没有没有错误的.

#include<stdio.h>
#i nclude"definition.h"

void Init(component *L)//初始化静态链表
{ unsigned short i;

for(i=0; i<MAXSIZE-1; i++)
L[i].cur=i+1;
L[MAXSIZE-1].cur=0;
}

component* Insert(component *L)//插入数据到链表
{ component *T, *temp1, *temp2;
unsigned short i;
ElemType ch;

if( i=Malloc(L) ){
T=temp1=&L[i];
T->cur=0;
} else
return 0;
while( (ch=getchar()) != '\n' ){
if( i=Malloc(L) ){
temp2=&L[i];
temp2->data=ch;
temp2->cur=0;
temp1->cur=i;
temp1=temp2;
} else
return 0;
}

return T;
}

short Malloc(component *L)//分配空间
{ unsigned short i;

i=L[0].cur;
if(L[0].cur){
L[0].cur=L[i].cur;
return i;//成功返回空间位置
}

return 0;//失败返回0
}

void Free(component *L, short i) //回收空间
{ L[i].cur=L[0].cur;
L[0].cur=i;
}