如何释放Adjency Linked List分配的内存?

时间:2017-05-06 18:48:31

标签: c memory-management free dynamic-memory-allocation

我想释放一个Adjency Linked List内存 这是我的数据结构和两个可以为图形分配内存的函数。 如何释放分配的内存? 谢谢你的帮助

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;
}

1 个答案:

答案 0 :(得分:0)

以下代码将成为您正在寻找的问题:

mix