高手解决一下拉,这题怎么弄啊
在LinkList.c的程序中加入单链表的头插法建立和尾插法建立,以及在单链表中插入和删除结点,把链表中的结点信息输出.具体的程序框架已经
存在,填充完毕即可。
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define ERROR 0
#define OK 1
#define EQUAL 1
#define OVERFLOW -1
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef char ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}sqlist;
int init(sqlist *L)
{
L->elem=(ElemType *)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L->elem) exit(OVERFLOW);
L->length=0;
L->listsize=LIST_INIT_SIZE;
return OK;
}
int ListLength(sqlist *L)
{
return L->length;
}
void GetElem(sqlist L,int i,ElemType *e)
{
*e=L.elem[i];
}
int EqualList(ElemType *e1,ElemType *e2)
{
if (e1==e2)
return 1;
else
return 0;
}
int Less_EqualList(ElemType *e1,ElemType *e2)
{
if (e1<e2)
return 1;
else
return 0;
}
int LocateElem(sqlist *La,ElemType e,int type)
{
int i;
switch (type)
{
case EQUAL:
for(i=0;i<La->length;i++)
if(EqualList(&La->elem[i],&e))
return 1;
break;
default:
break;
}
return 0;
}
int ListInsert(sqlist *L,int i,ElemType e)
{
ElemType *p,*q;
if (i<1||i>L->length+1) return ERROR;
q=&(L->elem[i-1]);
for(p=&L->elem[L->length-1];p>=q;--p)
*(p+1)=*p;
*q=e;
++L->length;
return OK;
}/*ListInsert Before i */
int listdelet(sqlist *l,int i,ElemType *e)
{
ElemType *p,*q;
if ((i<1)||(i>l->length)) return 0;
p=&(l->elem[i-1]);
*e=*p;
q=l->elem+l->length-1;
for(++p;p<=q;++p)
*(p-1)=*p;
--l->length;
return OK;
}
int printlist(sqlist L)
{
int i;
for(i=0;i<L.length;i++)
printf("%c\t",L.elem[i]);
printf("\n");
}
main()
{
ElemType e;
sqlist La,Lb,Lc;
}