`typedef struct
{
int a;
}ElemType;
struct SqList
{
ElemType *elem;//存储空间基址
int length;//当前长度
int listsize;//当前分配的存储容量
};
Status PriorElem(SqList L, ElemType cur_e, ElemType &pre_e)
{
//若cur_e是L的数据元素,且不是第一个,则用pre_e返回它的前驱
//否则操作失败,pre_e无定义
int i = 2;
ElemType *p = L.elem + 1;
while (i <= L.length && (*p) != cur_e)
{
p++;
i++;
}
if (i > L.length)
{
return INFEASIBLE;//操作失败
}
else
{
pre_e = *–p;
return OK;
}
}
`
问题原因:
结构类型的变量不能直接比较,以上结构可以换成 typedef int ElemType;
或者自定义符号。