-
Notifications
You must be signed in to change notification settings - Fork 0
/
a5.h
107 lines (60 loc) · 1.58 KB
/
a5.h
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Author: Nuoyu Yang Date: Feb. 22, 2019.
#ifndef A5_H
#define A5_H
#include <stdio.h>
#include <float.h>
#include <stdlib.h>
#include <string.h>
#define MAX_HEAP_SIZE 2000
#define INFINITY DBL_MAX
#define MAX_LINE_SIZE 20000
#define MAX_CITY_NAME 100
#define MATRIX_SIZE 1000
// Record in Heap
struct dis {
int node;
double weight;
int path[MATRIX_SIZE];
};
typedef struct dis Dis;
// Heap
struct minHeap {
int size;
Dis* heap[MAX_HEAP_SIZE];
};
typedef struct minHeap MinHeap;
// Node in Graph
struct node {
int vertex;
int weight;
struct node* next;
};
typedef struct node Node;
// heap functions
int left(int index);
int right(int index);
void heapify(MinHeap* H, int index);
void buildHeap(MinHeap* H);
Dis* popMin(MinHeap* H);
void push(MinHeap* H, Dis* newDis);
MinHeap* createHeap();
void initialize(MinHeap* H, int size, int start);
void destroyHeap(MinHeap* H);
// Helper Function
int getNode(char** cities, char* city);
// Djikstra Matrix Functions
char** createCities();
void DestoryCities(char** cities);
double** createGraphMatrix();
void destroyGraphMatrix(double** graph);
void readFileMatrix(double** graph, char** cities);
void relaxMatrix(Dis* u, Dis* v, double** graph);
Dis* djikstraMatrix(int start, int end, double** graph, int size);
// Djikstra List Functions
Node** createGraphList();
void destroyGraphList(Node** graph);
void readFileList(Node** graph, char** cities);
int adjacentDisList(Node* pin, MinHeap* H);
void relaxList(Dis* u, Node* pin, MinHeap* H);
Dis* djikstraList(int start, int end, Node** graph, int size);
#endif