-
Notifications
You must be signed in to change notification settings - Fork 31
/
algo.h
169 lines (144 loc) · 3.03 KB
/
algo.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*
* _____
* ANSI / ___/
* / /__
* \___/
*
* Filename: algo.h
* Author : Dan Levin
* Date : Mon Feb 16 10:06:22 2015
* Version : 0.51
* ---
* Description: Miscellanoeus algorithms
*
* Date Revision message
* 150331 This code ready for version 0.51
*
*/
/**
* @file algo.h
**/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <malloc.h>
#include <assert.h>
#include <float.h>
#include <math.h>
#include "slist.h"
#include "queue.h"
#include "graph.h"
#ifndef _ALGO_H_
#define _ALGO_H_
#ifdef __cplusplus
extern "C" {
#endif
/**
* A data structure for finding the shortest path between vertices in a graph
*
**/
typedef struct DspVertexdata_
{
/**
* Pointer to optional vertex data..
*
**/
void *data;
double weight;
VertexColor color;
double distance;
/* Pointer to parent vertex */
struct DspVertexdata_ *parent;
} *DspVertexdata;
/**
* A data structure for finding the minimum spanning tree in a graph
*
**/
typedef struct MstVertexdata_
{
/**
* Pointer to optional vertex data..
*
**/
void *data;
double weight;
VertexColor color;
double key;
/* Pointer to parent vertex */
struct MstVertexdata_ *parent;
} *MstVertexdata;
/**
* A data structure for finding the travelling salesmans route in a graph
*
**/
typedef struct TspVertexdata_
{
/**
* Pointer to optional vertex data..
*
**/
void *data;
double x, y;
VertexColor color;
} *TspVertexdata;
/**
* A data structure for vertices in a breadth-first search
*
**/
typedef struct BfsVertexdata_
{
/**
* Pointer to optional vertex data..
*
**/
void *data;
int hops;
VertexColor color;
} *BfsVertexdata;
/**
* A data structure for vertices in a depth-first search
*
**/
typedef struct DfsVertexdata_
{
/**
* Pointer to optional vertex data..
*
**/
void *data;
VertexColor color;
} *DfsVertexdata;
/* --- Function interface/declarations --- */
/**
* Find shortest path with Dijkstra's algorithm
*
**/
int ALGOdsp(Graph gr, const DspVertexdata start, Slist *spath,
int (*match)(const void *key1, const void *key2));
/**
* Find minimal spanning tree with Prims's algorithm
*
**/
int ALGOmst(Graph gr, const MstVertexdata start, Slist *span,
int (*match)(const void *key1, const void *key2));
/**
* Find route for Travelling Salesman
*
**/
int ALGOtsp(Slist vertices, const TspVertexdata start, Slist *tour,
int (*match)(const void *key1, const void *key2));
/**
* Do a breadth-first search in a graph
*
**/
int ALGObfs(Graph gr, const BfsVertexdata start, Slist *hops,
int (*match)(const void *key1, const void *key2));
/**
* Do a depth-first search in a graph
*
**/
int ALGOdfs(Graph gr, Slist *ordered);
#ifdef __cplusplus
}
#endif
#endif /* _ALGO_H_ */