求指导,帮我看看下面三个实验错在哪
一:#include<stdio.h>
#include<malloc.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define TRUE 1
typedef int Status;
//-------顺序表类型及其基本操作函数的定义---------
#define InitSize 100
#define I 20
typedef int ElemType;
typedef struct
{ ElemType *Elem;
int Length;
int ListSize;
}SqList; //SqList类型为顺序表类型
//初始化操作
Status InitList(SqList &L) `
{
L.Elem=(ElemType *)malloc(InitSize*sizeof(ElemType));
if (!(L.Elem)) return(OVERFLOW);
L.Length=0; L.ListSize=InitSize;
return OK;
}
//插入操作
Status ListInsert(SqList &L, int i, ElemType x)
{
int j;
if (i<1||i>L.Length+1) printf("位置非法"); return ERROR;
if (L.Length>=L.ListSize)
{ L.Elem=( ElemType *)malloc((L.ListSize+I)*sizeof(ElemType));
if(!(L.Elem)) return(OVERFLOW);
L.ListSize+=I;
}
for(j=L.Length-1;j>=i-1;j--)
L.Elem[j+1]=L.Elem[j];
L.Elem[i-1]=x;
L.Length++;
return OK;
}
//删除操作
Status ListDelist(SqList &L,int i,ElemType *e)
{ int k;
if (i<1||i>L.Length+1) { printf("位置非法"); return ERROR;}
*e=L.Elem[i-1];
for(k=i;k<=L.Length;k++)
L.Elem[k-1]=L.Elem[k];
L.Length--;
return OK;
}
//取元素操作
int ListGet(SqList &L,ElemType e)
{
int i=0;
while((i<=L.Length-1)&&(L.Elem[i]!=e))
i++;
if(i<=L.Length-1) return(L.Elem[i]);
else return ERROR;
}
//顺序表输出操作
void ListOutput(SqList L)
{ int i;
for(i=0;i<=L.Length-1;i++)
printf("%6d",L.Elem[i]);
printf("\n");
}
//-------------主函数定义--------------------
void main()
{ SqList L;
int i;
InitList(L);
for (i=0;i<6;i++)
ListInsert(L,i+1,2*i);
ListOutput(L);
ListInsert(L,1,66); ListOutput(L);
ListDelist(L,2,&47); ListGet(L,4);
ListInsert(L,3,77); ListOutput(L);
ListInsert(L,L.Length+1,888); ListOutput(L);
}
二:
#include <stdio.h>
#include <malloc.h>
#define OK 1
#define ERROR 0
#define OVERFLOW -2
#define TRUE 1
#define FALSE 0
typedef int Status;
//------------单链表类型及其基本操作函数的定义------
typedef int ElemType;
typedef struct Node
{ ElemType data;
struct Node *next;
}*LinkList;
Status InitList(LinkList &L)
{ L=(LinkList)malloc(sizeof(struct Node));
if(!L) return(OVERFLOW);
L->next=NULL;
return OK;
}
//插入操作
Status ListInsert(LinkList &L,int i, ElemType e)
{ LinkList p,s;
int j;
p=L;j=0;
while(p&&jnext;j++;}
if (!p||j>i-1) return ERROR;
s=(LinkList)malloc(sizeof(struct Node));
s->data=e;
s->next=p->next;
p->next=s;
return OK;
}
//删除操作
Status DelList(LinkList L,int i,ElemType *e)
{
Node *p,*r;
int k;
p=L;k=0;
while(p->next!=NULL&&k<i-1)
{
p=p->next;
k=k+1;
}
if(k!=i-1)
{ printf("删除结点非法"); return ERROR; }
r=p->next;
p->next=p->next->next;
*e=r->data;
free(r);
return TRUE;
}
//取元素操作
int *GetList(LinkList L;ElemType e)
{
int j;
Node *p;
p=L;j=0;
while(p->next!=NULL&&e!=H->elem[j])
{
p=p->next;
j++;
}
if(p->next=NULL) return ERROR;
else return(*p)
}
//输出操作
void ListOutput(LinkList L)
{ LinkList p;
p=L->next;
while(p)
{ printf("%6d",p->data); p=p->next; }
printf("\n");
}
//-------------主函数定义------------------
void main()
{ int i;
LinkList La;
InitList_l(La);
for (i=0;i<5;i++) ListInsert(La,i+1,3*i);
ListOutput(La); DelList(L,5,78);
GetList(L;99);
ListInsert(La,1,999); ListOutput(La);
ListInsert(La,4,888); ListOutput(La);
}
三:
#include<stdio.h>
#include<malloc.h>
typedef struct PNode
{ int C;
int E;
struct PNode *next;
}*POLY;
void CreatPoly(POLY &L,int n)
{ int i,C,E;
POLY p,s;
L=(POLY)malloc(sizeof(struct PNode));
L->next=NULL;
p=L;
for(i=1;i<=n;i++)
{ printf("input %dth C:",i);
scanf("%d",&C);
printf("input %dth E:",i);
scanf("%d",&E);
s=(POLY)malloc(sizeof(struct PNode));
s->C=C;s->E=E;
s->next=NULL;p->next=s;p=s;
}
}
void OutputPoly(POLY L)
{ int flag=1;
POLY p;
p=L->next;
while(p)
{ if(flag) { printf("%dX^%d",p->C,p->E); flag=0; }
else printf("%+dX^%d",p->C,p->E);
p=p->next;
}
printf("\n");
}
void AddPoly(POLY La, POLY Lb, POLY &Lc)
{ int x;
POLY pa,pb,pc,s;
Lc=(POLY)malloc(sizeof(struct PNode));
Lc->next=NULL;pc=Lc;
pa=La->next;pb=Lb->next;
while(pa&&pb)
{ if(pa->E->E)
{ s=(POLY)malloc(sizeof(struct PNode));
s->C=pa->C;s->E=pa->E;
s->next=NULL;pc->next=s;pc=s;
pa=pa->next;
}
else if(pa->E>pb->E)
{ s=(POLY)malloc(sizeof(struct PNode));
s->C=pb->C;s->E=pb->E;
s->next=NULL;pc->next=s;pc=s;
pb=pb->next;
}
else
{ x=pa->C+pb->C;
if(x!=0)
{ s=(POLY)malloc(sizeof(struct PNode));
s->C=x;s->E=pa->E;
s->next=NULL;pc->next=s;pc=s;
}
pa=pa->next; pb=pb->next;
}
}
while(pa)
{ s=(POLY)malloc(sizeof(struct PNode));
s->C=pa->C;s->E=pa->E;
s->next=NULL;pc->next=s;pc=s;
pa=pa->next;
}
while(pb)
{ s=(POLY)malloc(sizeof(struct PNode));
s->C=pb->C;s->E=pb->E;
s->next=NULL;pc->next=s;pc=s;
pb=pb->next;
}
}
void main()
{ POLY La,Lb,Lc;
int n;
printf("Creat Poly La:\n");
printf("\t Input the number of items of La:");
scanf("%d",&n);
CreatPoly(La,n);
printf("\nLa(x)=");
OutputPoly(La);
printf("Creat Poly Lb:\n");
printf("\tInput the number of items of Lb:");
scanf("%d",&n);
CreatPoly(Lb,n);
printf("\nLb(x)=");
OutputPoly(Lb);
AddPoly(La,Lb, Lc);
printf("Lc(x)=La(x)+Lb(x)=");
OutputPoly(Lc);
}