In the post《数据结构算法实现及解析》—配合严蔚敏_吴伟民编....jing314提供数据[长] [  2 3 4 ], there is source code for ListInsert, which has a memory leak bug:
This statment returns ERROR before freeing allocated memory = memory leak
return ERROR;
Sorry for working on system without Chinese input.
Status ListInsert(PNode *L, int i, ElemType e)
{ /* 在不带头结点的单链线性表L中第i个位置之前插入元素e */
    int j=1;
    PNode p=*L, s;
    if(i<1) /* i值不合法 */
        return ERROR;
    s=(PNode)malloc(sizeof(struct Node)); /* 生成新结点 */
    s->data=e; /* 给s的data域赋值 */
    if(i==1) /* 插在表头 */
    {
        s->next=*L;
        *L=s; /* 改变L */
    }
    else
    { /* 插在表的其余处 */
        while(p&&j<i-1) /* 寻找第i-1个结点 */
        {
            p=p->next;
            j++;
        }
        if(!p) /* i大于表长+1 */
            return ERROR;
        s->next=p->next;
        p->next=s;
    }
    return OK;
}
[此贴子已经被作者于2007-6-10 6:53:25编辑过]



											

	    

	
