用VS2010写C语言数据结构遇到有关问题
用VS2010写C语言数据结构遇到问题
VS2010 ,文件结尾为.c,实现顺序线性表的一个功能。编译的时候提示“错误 1 error C2275: “ElemType”: 将此类型用作表达式非法”
VC6.0中无错
求教!!!
------解决方案--------------------
typedef int Status;
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 4
typedef int ElemType;
改成
typedef int Status;
typedef int ElemType;
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 4
之后试试。
VS2010 ,文件结尾为.c,实现顺序线性表的一个功能。编译的时候提示“错误 1 error C2275: “ElemType”: 将此类型用作表达式非法”
VC6.0中无错
#include <stdio.h>
#include <stdlib.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef int Status;
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 4
typedef int ElemType;
typedef struct SqList
{
ElemType * elem;
//表的初始长度
int length;
//表的初始存储容量
int listsize;
}SqList;
Status ListInsert_Sq(SqList *L, int i, ElemType e){
//判断插入位置i是否合法
if (i < 1 || i > L->length + 1)
return ERROR;
//判读存储空间是否已满
if (L->length >= L->listsize){
ElemType * newbase = (ElemType *)realloc(L->elem, (L->listsize + LISTINCREMENT) * sizeof(ElemType));
if (!newbase)
exit(OVERFLOW);
L->elem = newbase;
L->listsize = L->listsize + LISTINCREMENT;
}
//q指向第i个元素
ElemType *q = &(L->elem[i - 1]);
//p指向最后一个元素
ElemType *p;
//从最后一个位置开始移动
for (p= &(L->elem[L->length - 1]); p >= q; p--) {
*(p + 1) = *p;
}
*q = e;
L->length++;
return OK;
}
求教!!!
c
数据结构
------解决方案--------------------
typedef int Status;
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 4
typedef int ElemType;
改成
typedef int Status;
typedef int ElemType;
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 4
之后试试。