命运之轮正位爱情 未来:c语言程序,能编译但不能连接,下面是3个文件,分开放,有高加分的

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/18 22:16:42
文件1 #define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList_Sq(SqList *L){
L->elem = (ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
L->length = 0;
L->listsize = LIST_INIT_SIZE;
return OK;
}
Status ListInsert_Sq(SqList *L, int i, ElemType e){
int j;
if( i<1 || i>L->length+1 ) return(ERROR);
if( L->length >= L->listsize) return(ERROR);
for(j = L->length-1; j>=i-1; --j) L->elem[j+1] = L->elem[j];
L->elem[i-1] = e;
++(L->length);
return OK;
}
Status ListDelete_Sq(SqList *L, int i, ElemType *e){
int j;
if( (i<1) || (i>L->length) ) return ERROR;
*e = L->elem[i-1];
for(j = i; j<=L->length-1; ++j) L->elem[j-1] = L->elem[j];
--(L->length);
return OK;
}
Status GetElem_Sq(SqList L, int i, ElemType *e){
int j;
if( (i<1) ||(i>L.length) ) return ERROR;
*e = L.elem[i-1];
return OK;
}
Status DetroyList_Sq (SqList *L) {
free(L);
return OK;
}

void MergeList_Sq(SqList La, SqList Lb, SqList *Lc){

int i=1,j=1,k=0;
int m,n;

InitList(Lc);
m=La.length;n=Lb.length;
while((i<=m)&&(j<=n))
{GetElem(La,i,La.elem[i]);GetElem(Lb,j,Lb.elem[j]);
if(La.elem[i]<=Lb.elem[j]){ListInsert(Lc,++k,La.elem[i]);++i;}
else{ListInsert(Lc,++k,Lb.elem[j]);++j;}
}
while(i<=m)
{
GetElem(La,i++,La.elem[i]);ListInsert(Lc,++k,La.elem[i]);
}
while(j<=n)
{
GetElem(Lb,j++,Lb.elem[j]);ListInsert(Lc,++k,Lb.elem[j]);
}

}

文件2#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
主程序:

#include <stdio.h>
#include <stdlib.h>
#include "predef.c"
typedef int ElemType;
#include "SqList.c"
void main( ){
int i, n;
ElemType e;
SqList L, La,Lb,Lc ;
InitList_Sq(&L);
InitList_Sq(&La);
InitList_Sq(&Lb);
InitList_Sq(&Lc);

printf("the number of Element?\t");
scanf("%d", &n);
printf("input your Elements:\n");
for(i=1; i<=n; ++i){
scanf("%d",&e);
ListInsert_Sq(&L, i, e);
}
printf("the result of GetElem operation:\n");
for(i=1; i<=n; ++i){
GetElem_Sq(L, i, &e);
printf("%d\t%d\n", e, L.length);
}
printf("the result of ListDelete operation:\n");
for(i=1; i<=n; ++i){
ListDelete_Sq(&L, 1, &e);
printf("%d\t%d\n", e, L.length);
}

printf("input your Elements of La:\n");
for(i=1; i<=n; ++i){
scanf("%d",&e);
ListInsert_Sq(&La, i, e);
}

printf("input your Elements of Lb:\n");
for(i=1; i<=n; ++i){
scanf("%d",&e);
ListInsert_Sq(&Lb, i, e);
}

InitList_Sq(&Lc);
printf("the result of Mergelist operation:\n");
for(i=0;i<(La.length+Lb.length);i++)

{
MergeList_Sq( La, Lb, &Lc);
GetElem_Sq(Lc, i, &e);
printf("%d\n",e);
}

DestroyList_Sq(&Lc);

}

#include "predef.c"
typedef int ElemType;
#include "SqList.c

最好将predef.c SqList.c改为SqList.h头文件后最形式