|
5啊哈币
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define MAX_SIZE 100
#define OK 1
#define ERROR -1
typedef int status;
typedef int ElemType;
typedef struct sqlist
{
ElemType e_array[MAX_SIZE];
int length;
}SqList;
struct books
{
int num;
char name[20];
char author[20];
int position;
}book[MAX_SIZE];
//线性表初始化
Status InitList_Sq(SqList *L){
L->e_array=(ElemType * )malloc(MAX_SIZE * sizeof(ElemType));
if(! L->e_array) return ERROR; //存储分配失败
else{
L->length=0; //空表长度为0
return OK;
}
}
//线性表的插入
Status ListInsert_Sq(SqList *L, int i, ElemType e){
int j;
if(i<0 || i>L->length-1) return ERROR;
if(L->length>=MAX_SIZE){
printf("线性表溢出\n"); return ERROR;}
for(j=L->length-1;j=i-1;--j)
L->e_array[j+1]=L->e_array[j];
L->e_array[i-1]=e;
L->length++;
return OK;
}
//线性表的删除
ElemType ListDelect_Sq(SqList *L, int i){
int k;
ElemType x;
if(L->length==0) {
printf("线性表L为空\n");
return ERROR;
}
else if(i<0||i>L->length){
printf("要删除的数据元素不存在\n");
return ERROR;
}
else {x=L->e_array[i-1]; //保存结点的值
for(k=i;k<L->length;k++)
L->e_array[k-1]=L->e_array[k]; //i位置以后的所有结点前移
L->length--;
return (x);
}
}
int LocateElem_Sq(SqList *L, ElemType x){
int i=0;
while(i<L->length) //查找值为x的第一个结点
{
if(L->e_array[i]!=x) i++;
else {return book[i];}
}
if(i>L->length){
printf("要查找的数据元素不存在\n");
return ERROR;
}
}
//归并La和Lb得到新的线性表Lc
void MergeList_Sq(SqList La,SqList Lb,SqList &Lc){
InitList(Lc);
i=j=1; k=0;
pa=ListLength(La); pb=ListLength(Lb);
while((i<=pa) && (j<=pb)){ //La和Lb为非空
GetElem(La,i,ai); //从La中取第i个元素给ai
GetElem(Lb,j,bj)
if(ai<=bj) {ListInsert(Lc,++k,ai);++i;}
else {ListInsert(Lc,++k,bj);++j;}
}
while(i<pa){
GetElem(La,i++,ai); ListInsert(Lc,++k,ai);
}
while(j<=pb){
GetElem(Lb,j++,bj); ListInsert(Lc,++k,bj);
}
}
int main()
{
printf("请输入书本数据:\n");
int i;
for(i=0;i<3;i++)
scanf("%d%s%s",&book[i].num,book[i].name,book[i].author,book[i].position);
return 0;
}
//////编译时出现的错误,,求帮忙解决,谢谢
E:\C程序\数据结构—1.cpp(27) : error C2146: syntax error : missing ';' before identifier 'InitList_Sq'
E:\C程序\数据结构—1.cpp(27) : error C2501: 'Status' : missing storage-class or type specifiers
E:\C程序\数据结构—1.cpp(27) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
数据结构—1.exe - 1 error(s), 0 warning(s)
|
|