forked from vicentebolea/dijkstra_binaryHeap_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adjacencyList.h
59 lines (47 loc) · 1.32 KB
/
adjacencyList.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
/**
* Assignment 5 for CSE231 Data Structures
*
* 2012. 10. 8
*
* FILE: adjacencyList.h
* DESCRIPTION: This file contains the declaration and
* definition of the ADT adjacency list.
* This adjacency list has a vector of chain
* which is initializate by the constructor.
*
* AUTHOR: Vicente Adolfo Bolea Sanchez
* STUDENT NO: 20122901
* EMAIL: vicente.bolea@gmail.com
*/
#ifndef _ADJACENCY_LIST_
#define _ADJACENCY_LIST_
#include "minheap.h" /* Only needed for elemHeap class */
#include "chain.h" /* Needed since a A.L. is a vector of chain */
//Make names simplers :D
typedef chain<heapElem>::iterator Iterator;
class adjacencyList {
private:
chain<heapElem>* vector;
public:
adjacencyList (int _vertices) {
vector = new chain<heapElem>[_vertices];
}
~adjacencyList () {
delete[] vector;
}
/* Build the given chain */
void insert (int index, const heapElem& item) {
vector[index].push(item);
//For the another vertex
vector[item.idx].push(heapElem(index, item.dist));
}
/* return the begin for a given vertice */
inline Iterator beginAt(int index) const {
return Iterator (vector[index].begin());
}
/* return the end for a given vertice */
inline Iterator endAt(int index) const {
return Iterator (vector[index].end());
}
};
#endif