c语言结构体释放内存,结构体,链表,释放内存出错

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

}

/*

Compare two PhoneRecord structures

Returns -1 if the name for the first is < name for the second

Returns   0 if the name for the first is equal to the name for the second

Returns +1 if the name for the first is > name for the second

*/

int compare_records(struct PhoneRecord *pFirst, struct PhoneRecord *pSecond)

{

return compare_names(pFirst->name, pSecond->name);

}

/* Compare two names

Returns -1 if the   first is < the second

Returns   0 if the first is equal to tthe second

Returns +1 if the first is >   the second

The comparison is by second name. If second names are equal,

first names are compared.

*/

int compare_names(struct Name first, struct Name second)

{

int result = 0;

result = strcmp(first.secondname,second.secondname);

return (result != 0 ? result : strcmp(first.firstname,second.firstname));

}

/* Insert a node into the list */

void insert_node(struct Node *pNode)

{

struct Node *pCurrent = NULL;

struct Node *pPrevious = NULL;

/* Check for empty list */

if(!pStart)

{

pStart = pNode;    /* Store address of the node as the start node */

return;

}

/* Find position to insert the new node */

pCurrent = pStart;

while(pCurrent)

{

if(compare_records(pNode->pRecord, pCurrent->pRecord) <= 0)

{                           /* New node goes before current list node */

pNode->pNext = pCurrent; /* Set new node next pointer to current    */

if(!pPrevious)            /* If pCurrent is the first node           */

{

pNode->pNext = pStart; /* New node next pointer points to current */

pStart = pNode;         /* New node is the first node               */

}

else

{                            /* Otherwise... */

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值