小弟菜鸟一枚,请大家关照
#include<stdio.h>//#include "ghy-list.h"
#define maxsize 100
#include "SqList.cpp"
typedef int Elem Type;
typedef struct
{
Elem Type data[MaxSize] ;
int length;
} SqList;
void InitList(SqList &L)
{
L.length=0;
}
void DestoryList(SqList L)
{}
int GetLength(Sqlist L)
{
return L.length;
}
int GetElem(SqList L,int i,ElemType &e)
{
if(i<1||i>L.length)
return 0;
else
{
e=L.data[i-1];
return 1;
}
}
int Locate(SqList L,ElemType x)
{
int i=0;
while(i<L.length&&L.data[i]!=x)
i++;
if(i>=L.length) return(0);
else return(i+1);
}
int InsElem(SqList &L,ElemType x,int i)
{
int j;
if(i<1||i>L.length+1)
return 0;
for(j=L.length;j>i;j--)
L.data[j]=L.data[j-1]
L.data[i-1]=x;
L.length++;
return 1;
}
int DelElem(SqList&L,int i)
{
int i;
if(i<1||i>L.length)
return 0;
for(j=i;j<L.length;j++)
L.data[j-1]=L.data[j];
L.length--;
return 1;
}
void DispList(SqList L)
{
Int i;
for(i=0;i<L.length;i++)
printf("%d",L.data[i]);
printf("\n");
}
void CreatList(SqList &L,ElemType a[],int n)
{
inti,k=0;
for(i=0;i<n;i++)
{
L.data[k]=a[i];
k++;
}
L.length=k;
}
int main()
{
int i;
ElemType e;
SqList L,L1;
InitList(L);
InsElem(L,1,1);
InsElem(L,3,2);
InsElem(L,1,3);
InsElem(L,5,4);
InsElem(L,4,5);
InsElem(L,2,6);
printf("测试1\n");
printf("L:");DispList(L);
printf(" 长度;%d\n",GetLength(L));
i=3;
GetElem(L,i,e);
printf("第%d个元素:%d\n",i,e) ;
e=1;
printf(" 元素%d是第%d个元素\n",e,Locate(L,e));
i=4;printf(" 删除第%d个元素\n",i);
DelElem(L,i);
printf(" L: ");DispList(L);
printf("测试2\n");
int a[]={2,5,4,5,6,5,3,1};
int n=sizeof(a)/sizeof(a[0]);
printf(" 整体创建L1\n");
CreatList(L1,a,n);
printf(" L1:");DispList(L1);
int x=5;
printf(" 第一个值为%d元素的位置是%d\n",x,Locate(L1,x));
printf("销毁L和L1\n");
DestoryList(L);
DestoryList(L1);
}
//4 22 C:\Users\HP\Desktop\Untitled1.cpp [Error] SqList.cpp: No such file or directory 这该怎么解决呀?