-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinaryheap.h
More file actions
53 lines (43 loc) · 1.22 KB
/
binaryheap.h
File metadata and controls
53 lines (43 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#ifndef BINARYHEAP_H
#define BINARYHEAP_H
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <time.h>
#define MAX_NODES 100000
#define INF INT_MAX
typedef struct AdjNode {
int vertex;
int weight;
struct AdjNode* next;
} AdjNode;
typedef struct {
int num_nodes;
AdjNode** adj_list;
} Graph;
typedef struct {
int distance;
int vertex;
} HeapNode;
typedef struct {
HeapNode* array;
int size;
int capacity;
} MinHeap;
Graph* create_graph(int num_nodes);
void add_edge(Graph* graph, int u, int v, int weight);
void free_graph(Graph* graph);
MinHeap* create_min_heap(int capacity);
void swap_heap_nodes(HeapNode* a, HeapNode* b);
void min_heapify(MinHeap* heap, int idx);
int is_empty(MinHeap* heap);
HeapNode extract_min(MinHeap* heap);
void decrease_key(MinHeap* heap, int vertex, int distance);
int is_in_heap(MinHeap* heap, int vertex);
void dijkstra(Graph* graph, int src, int* dist, int* prev);
void print_path(int* prev, int target);
void reconstruct_path(int* prev, int target, int* path, int* path_length);
int shortest_path_length(Graph* graph, int src, int target, int* path, int* path_length);
Graph* read_file(const char* filename);
#endif