标签:new maxsize style nbsp error insert overflow 顺序表 i+1
typdef struct {
Element *elem;
int length;
}
status InitList(SqList &L){
L.elem = new Element[MAXSIZE];
if(!L.elem) exit(OVERFLOW)
L.length = 0;
return Ok;
}
status GetList(SqList L,ElemType &e,int i){
if(i<1||i>L.length)
return ERROR;
e = L.elem[i-1];1
return OK;
}
status LocalList(SqList L,Element e,int i){
for(i = 0;i<L.length;i++)
if(e == l.elem[i])
return i+1;
return 0;
}
status ListInsert(SqList &L,int i,ElemType e){
if(i<1||(i>L.length+1)) return ERROR;
if(L.length = MAXSIZE)
return ERROR;
for(j=L.length-1;j>=i-1;--j)
L.elem[j+1]=L.elem[j]; //L.elem[j]=L.elem[j-1];思考这里为什么是错的
L.elem[i-1]=e;
return OK;}
status ListDelete(SqList &L,int i){
if((i<1)||(i>L.length))
return ERROR;
for(j = i;j<L.length-1;j++)
L.elem[j-1] = L.elem[j];
--L.length;
return OK;
}
//根据具体事例考究SqList &L SqList L的区别
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
status InitList(LinkList L,int i,ElemType &e){
L = new LNode;
L->next = Null;
return Ok;
}
status GetElemList(LinkList &L,int n){
p = L->next;
j = 1;
while(p&&j<i){
p=p->next;
++j;
}
if(j>i||!p)
return ERROR;
e = p->data;
return OK;
}
LNode *LocalElem(LinkList L,ElemType e){
p = l->next;
while(p && p ->data ! = e)
p=p->next;
return P;
}
status
标签:new maxsize style nbsp error insert overflow 顺序表 i+1
原文地址:http://www.cnblogs.com/wanghui626/p/6012308.html