注册 登录
编程论坛 数据结构与算法

这个删除算法错在了哪里

qweiuy566 发布于 2016-04-11 21:39, 3255 次点击
typedef int Status;
typedef char ElemType;
#include "status.h"
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10

class SqList{
private:
    ElemType *elem;
    int length;
    int listsize;
public:
    Status DestroyList();
};
//以下是我的删除算法,前面是定义的类
Status SqList::DestroyList()
{
    ElemType Head, P;
    if(length)  //若线性表L已存在
{
    Head=*elem;
    P=Head+1;
    while(!P) //把链表中除头结点外的所有结点释放
{
    free(Head);
    Head = P;
    P = Head+1;
}
    free(Head);//释放头结点  
    return OK;
}
    else
    return ERROR;
}
想了好久,也没明白。。。
2 回复
#2
huzi7412016-04-12 12:55
1:你的Head和P都不是指针,变量定义错误;
#3
超级无敌阳光2016-04-18 13:17
楼上正解,此外还有你线性表的长度应为L.length
1