【发布时间】:2018-09-04 01:59:21
【问题描述】:
#include <stdio.h>
#include <stdlib.h>
struct item {
int key;
int data;
struct item *next;
};
struct item *head = NULL;
void delete(int key)
{
if(head == NULL) {
;
} else if(head->key == key) {
head = head->next;
} else {
struct item *curr = head;
struct item *prev = NULL;
int found = 0;
while(curr != NULL) {
if(curr->key == key) {
found = 1;
break;
} else if(curr->key > key) {
break;
}
prev = curr;
curr = curr->next;
}
if(found) {
prev->next = curr->next;
}
}
}
键已排序。 delete 接受一个键,然后将其删除。它有效,但我不明白什么时候可以免费使用。
我们必须释放()我们从列表中取消链接的结构项目
【问题讨论】:
标签: c