- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想释放邻接链表内存这是我的数据结构和两个可以为图形分配内存的函数。如何释放分配的内存?感谢您的帮助
struct ListPoint {
int dest;
int weight;
struct ListPoint* next;
};
struct List {
struct ListPoint* head;
};
struct Graf {
int V;
struct List* array;
};
struct ListPoint* newAdjencyListPoint(int dest, int weight)
{
struct ListPoint* newPoint =
(struct ListPoint*)malloc(sizeof(struct ListPoint));
newPoint->dest = dest;
newPoint->weight = weight;
newPoint->next = NULL;
return newPoint;
}
struct Graf* createGraph(int V)
{
struct Graf* graf = (struct Graf*)malloc(sizeof(struct Graf));
graf->V = V;
graf->array= (struct List*)malloc(V * sizeof(struct List));
int i;
for (i = 0; i < V; ++i)
graf->array[i].head = NULL;
return graf;
}
最佳答案
以下代码可能就是您正在寻找的代码:
freeLinkedList(struct List list){
struct ListPoint *aux,*it = list.head;
while(it != NULL){ //free a node and go to the next one
aux = it->next;
free(it);
it = aux;
}
}
freeAdjList(struct Graf* adj_list){
for(int i=0;i<adj_list->V;i++) //free each linked list
freeLinkedList(adj_list->array[i]);
free(adj_list->array); //free the linked list array
free(adj_list); //free the adj matrix itself
}
关于c - 如何释放邻接链表分配的内存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43824178/
我在 ma 应用程序中使用 Jqgrid 树 View 模型,我可以看到它显示错误,因为不支持对象或属性我已经包含了 grid.Treeview.js 和其他 Jqgrid 脚本文件。我不知道可能是什
我正在尝试使用图中所示的符号在 matlab 上实现 Freeman Chain Code [4 adjacency]: 我的代码为我测试过的多个小矩阵提供了正确的链码。但是,当我在我的实际图像文件上
我有一张表,其中包含世界上所有地理位置及其关系的位置。 这是一个显示层次结构的示例。你会看到数据实际上存储为所有三个 枚举路径 邻接表 嵌套集 数据显然也不会改变。下面是英格兰布莱顿位置的直系祖先示例
我正在尝试从邻接树模型(id、parent_id)中的 MySQL 数据库中计算/创建或生成 PHP 目录。到目前为止,这是我在回显输出时所取得的成就。 1. Category 1 1 Subc
我知道 std::vector在内部连续存储它的数据(除非它是 std::vector )都在旧的 C++03 中标准和新的C++11 . 处理此问题并引用标准的好 stackoverflow 问题:
Development language and DB: PHP/MySQL 我有一张 geo_places 表,其中包含大约 800 万个地理位置。 这些地方都是分层次的,我用 parent_id
过去几个小时我一直在尝试在网上找到这个问题的解决方案。我找到了很多关于如何从嵌套集合转换为邻接的例子......但很少有相反的例子。我发现的示例要么不起作用,要么使用 MySQL 过程。不幸的是,我不
我是一名优秀的程序员,十分优秀!