有关数据结构的一些问题
数据结构单链的程序(含clearlist ,getelem ,listdelete ,listinsert)以及主函数怎么写?例如
#include <iostream.h>
#include "stdlib.h"
#include "stdio.h"
#include "malloc.h"
#define OK 1
#define ERROR -2
#define OVERFLOW -1
typedef int ElemType;
typedef int status;
typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode, *Linklist
Status ClearList(&L)
{
}
Status GetElem_L(Linklist L,int i,Elemtype &e)
{
struct LNode *p = NULL;
p=L->next;j=1;
while(p&&j<1)
{
p=p->next;++j;
}
if(!p||j>i) return ERROR;
e=p->data; return OK;
}GetElem_L
Status ListInsert_L(Linklist &L,int i,ElemType e)
{
p=L;j=0;
while(p&&j<i-1){p=p->next;++j;}
if(!p||j>i-1) return ERROR;
s=(Linklist) malloc (sizeof(LNode));
s->data=e;s->next=p->next;
p->next=s;
return Ok;
}ListInsert_L
Status ListDelete_L(LinkList &L,int i,ElemType &e)
{
p=L;j=0;
while(p->next&&j<i-1)
{
p=p->next;
++j;
}
if(!(p->next)||j>i-1) return ERROR;
q=p->next; p->next=q->next;
e=q->data;
free(q);
return OK;
}ListDelete_L
int main()
{
LinkList L;
int i,p,q,s;
L.GetELem()
cout>>endl;
L.ListInsert()
cout>>endl;
L.ListDelete()
cout>>endl;
}