- 论坛徽章:
- 0
|
[fly]问题解决, 因为所包含的头文件没有定义一个ElemType类型, 所以一直报错.[/fly]
这是Status.h
#include <stdlib.h>
#include <stdio.h>
/* function return type code */
#define TURE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
/* Status is return type */
typedef int Status |
这是Sqlist.c
#include "Status.h"
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
struct SqList {
ElemType *elem;
int length;
int listsize;
};
typedef struct SqList SqList;
/* ALG 2.3 */
Status InitList_Sq(SqList *L) {
L->elem = (ElemType *)malloc(LIST_INIT_SIZE * sizeof(ElemType));
if(!L->elem)
exit(OVERFLOW);
L->length = 0;
L->listsize = LIST_INIT_SIZE;
return OK;
}/* InitList_Sq */
/* ALG 2.4 */
Status ListInsert_Sq(Sqlist *L, int i, ElemType e) {
if(i<0 || i>(L->length))
return ERROR;
if(L->length >= L->listsize) {
ElemType *newbase;
newbase = (ElemType *)realloc(L->elem,
(L->listsize + LISTINCREMENT) * sizeof(ElemType));
if(!newbase)
exit(OVERFLOW);
L->elem = newbase;
L->listsize += LISTINCREMENT;
}
ElemType *p, *q;
q = L->elem + i;
for(p = L->elem + l->length; p>q; --p)
*p = *(p - 1);
*q = e;
++L.length;
return OK;
}/* ListInsert_Sq */
/* ALG 2.5 */
Status ListDelete_Sq(Sqlist *L, int i, ElemType *e) {
if((i<0) || (i>(L->lenth - 1)))
return ERROR;
ElemType *p, *q;
p = L->elm + i;
*e = *p;
for(q = L->elem + L.length - 1; q>p; --q)
*(q - 1) = *q;
--(L->length);
return OK;
}/* ListDelete_Sq */
|
这是编译的错误信息
[mike@localhost datastc]$ gcc -Wall -c Sqlist.c
Sqlist.c:5: syntax error before "struct"
Sqlist.c:6: parse error before "ElemType"
Sqlist.c:6: warning: no semicolon at end of struct or union
Sqlist.c:9: parse error before '}' token
Sqlist.c:13: parse error before "InitList_Sq"
Sqlist.c:13: warning: return type defaults to `int'
Sqlist.c: In function `InitList_Sq':
Sqlist.c:14: dereferencing pointer to incomplete type
Sqlist.c:14: `ElemType' undeclared (first use in this function)
Sqlist.c:14: (Each undeclared identifier is reported only once
Sqlist.c:14: for each function it appears in.)
Sqlist.c:14: parse error before ')' token
Sqlist.c:15: dereferencing pointer to incomplete type
Sqlist.c:17: dereferencing pointer to incomplete type
Sqlist.c:18: dereferencing pointer to incomplete type
Sqlist.c: At top level:
Sqlist.c:23: parse error before "ListInsert_Sq"
Sqlist.c:23: parse error before '*' token
Sqlist.c:23: warning: return type defaults to `int'
Sqlist.c: In function `ListInsert_Sq':
Sqlist.c:24: `i' undeclared (first use in this function)
Sqlist.c:24: `L' undeclared (first use in this function)
Sqlist.c:28: `ElemType' undeclared (first use in this function)
Sqlist.c:28: `newbase' undeclared (first use in this function)
Sqlist.c:29: parse error before ')' token
Sqlist.c:37: `p' undeclared (first use in this function)
Sqlist.c:37: `q' undeclared (first use in this function)
Sqlist.c:37: warning: left-hand operand of comma expression has no effect
Sqlist.c:39: `l' undeclared (first use in this function)
Sqlist.c:41: `e' undeclared (first use in this function)
Sqlist.c: At top level:
Sqlist.c:47: parse error before "ListDelete_Sq"
Sqlist.c:47: parse error before '*' token
Sqlist.c:47: warning: return type defaults to `int'
Sqlist.c: In function `ListDelete_Sq':
Sqlist.c:48: `i' undeclared (first use in this function)
Sqlist.c:48: `L' undeclared (first use in this function)
Sqlist.c:50: `ElemType' undeclared (first use in this function)
Sqlist.c:50: `p' undeclared (first use in this function)
Sqlist.c:50: `q' undeclared (first use in this function)
Sqlist.c:50: warning: left-hand operand of comma expression has no effect
Sqlist.c:52: `e' undeclared (first use in this function)
[ 本帖最后由 argstormsky 于 2009-1-15 22:43 编辑 ] |
|