第一次敲线性表的代码 全是问题
题目是删除线性表中元素值在【x,y】之间的元素。这是参照书自己写的
程序代码:
#include<stdio.h> #include<string.h> #include<stdlib.h> #define i 0 void CreateList(SqList *&L,int a[],int n) { L=(SqList *)malloc(sizeof(SqList)); for(;i<n;i++) L->data[i]; L->length=n;[i]=a } int LocateElem(SqList *L,int e) { while(i<L->length && L->data[i]!=e) i++; if(i>=L->length) return 0; else return i+1; } bool ListDelete(SqList *&L,int i,int t) { int j; if(i<1 || i>L->length) return false; i--; for(j=i;j<L->length-t;j++) L->data[j]=L->data[j+t]; L->length-=t; return ture; } void DispList(SqList *L) { for(;i<L->length;i++) printf("%d",L->data[i]); printf("\n"); } int main() { void CreateList(SqList *&L,int a[],int n); int LocateElem(SqList *L,int e); bool ListDelete(SqList *&L,int i,int t); void DispList(SqList *L); int m,n,a[100],x,y,l; bool b; printf("请输入顺序数组a:\n"); for(;i<100;i++) { scanf("%d",a[i]); if(a[i]=='\n') break; } printf("x="); scanf("%d",x); printf("y="); scanf("%d",y); l=strlen(a); CreateList(L,a[l],l); n=LocateElem(L,x); m=LocateElem(L,y); m=m-n-1; b=ListDelete(L,n,m); if(b==ture) DDispList(L); else printf("删除失败!\n"); return 0; }
这是编译器报的错 好多啊
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2059: syntax error : '&'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(6) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2059: syntax error : 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(14) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2061: syntax error : identifier 'ListDelete'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2059: syntax error : ';'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2059: syntax error : '&'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(24) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(36) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(36) : error C2143: syntax error : missing '{' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(36) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(37) : error C2054: expected '(' to follow 'L'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2143: syntax error : missing ')' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2143: syntax error : missing ';' before '*'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2059: syntax error : 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(45) : error C2059: syntax error : ')'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(46) : error C2143: syntax error : missing ';' before 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2065: 'bool' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2146: syntax error : missing ';' before identifier 'ListDelete'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : warning C4013: 'ListDelete' undefined; assuming extern returning int
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2065: 'SqList' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2297: '*' : illegal, right operand has type 'int ** '
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(47) : error C2059: syntax error : 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(48) : error C2143: syntax error : missing ';' before 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(49) : error C2143: syntax error : missing ';' before 'type'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(50) : error C2146: syntax error : missing ';' before identifier 'b'
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(50) : error C2065: 'b' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(52) : error C2105: '++' needs l-value
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(54) : error C2065: 'a' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(54) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(55) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(58) : error C2065: 'x' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(60) : error C2065: 'y' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(61) : error C2065: 'l' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(61) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(61) : warning C4024: 'strlen' : different types for formal and actual parameter 1
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(62) : error C2109: subscript requires array or pointer type
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(63) : error C2065: 'n' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(63) : warning C4013: 'LocateElem' undefined; assuming extern returning int
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(64) : error C2065: 'm' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(67) : error C2065: 'ture' : undeclared identifier
D:\Microsoft Visual Studio\线性表P61T2.2\P61T2-2.c(68) : warning C4013: 'DDispList' undefined; assuming extern returning int
执行 cl.exe 时出错.