// Dijkstra_Heap.cpp: 定义控制台应用程序的入口点。
//基于堆实现Dijkstra算法
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <stdbool.h>
struct AdjListNode
{
int dest;
int weight;
struct AdjListNode * next;
};
struct AdjList
{
struct AdjListNode * head;
};
struct Graph
{
int VNum;
struct AdjList * array;
};
struct AdjListNode * newAdjListNode(int dest, int weight)
{
struct AdjListNode * newNode =
(struct AdjListNode *)malloc(sizeof(struct AdjListNode));
newNode->dest = dest;
newNode->weight = weight;
newNode->next = NULL;
return newNode;
}
struct Graph * createGraph(int VNum)
{
struct Graph * graph = (struct Graph *)malloc(sizeof(struct Graph));
graph->VNum = VNum;
graph->array = (struct AdjList *)malloc(VNum * sizeof(struct AdjList));
for (int i = 0; i < VNum; i++)
graph->array[i].head = NULL;
return graph;
}
void addEdge(struct Graph * graph, int src, int dest, int weight)
{
struct AdjListNode * newNode = newAdjListNode(dest, weight);
newNode->next = graph->array[src].head;
graph->array[src].head = newNode;
newNode = newAdjListNode(src, weight);
newNode->next = graph->array[dest].head;
graph->array[dest].head = newNode;
}
struct MinHeapNode {
int dest;
int dist;