Skip to content

Commit 27a3f68

Browse files
authored
Merge pull request #372 from BrianLusina/feat/graphs
Graphs | Vertex & Graph Data Structures
2 parents 1db7c31 + 2da3ecb commit 27a3f68

8 files changed

Lines changed: 25 additions & 82 deletions

File tree

DIRECTORY.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@
116116
* circular-buffer
117117
* [circular-buffer](https://github.com/BrianLusina/jtscripts/blob/master/datastructures/circular-buffer/circular-buffer.js)
118118
* [circular-buffer](https://github.com/BrianLusina/jtscripts/blob/master/datastructures/circular-buffer/circular-buffer.spec.js)
119-
* Graphs
120-
* [devbook](https://github.com/BrianLusina/jtscripts/blob/master/datastructures/Graphs/devbook.js)
121119
* hashmap
122120
* [HashMapJs](https://github.com/BrianLusina/jtscripts/blob/master/datastructures/hashmap/HashMapJs.js)
123121
* linkedlist
File renamed without changes.
File renamed without changes.
File renamed without changes.

datastructures/Graphs/minNumberofVertices/minNumberOfVertices.ts renamed to algorithms/graphs/minNumberofVertices/minNumberOfVertices.ts

File renamed without changes.

datastructures/Graphs/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Relevant Links
1+
# Graphs
22

3-
https://medium.freecodecamp.com/a-gentle-introduction-to-data-structures-how-graphs-work-a223d9ef8837#.4gl51zy2x
4-
https://www.tutorialspoint.com/data_structures_algorithms/graph_data_structure.htm
3+
Data structures representing graphs

datastructures/Graphs/Vertex.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default class Vertex<T> {
2+
private id: string;
3+
private data: T;
4+
private metadata: Map<string, unknown> | undefined;
5+
private adjacentVertices: Map<string, Vertex<T>>;
6+
7+
constructor(id: string, data: T, metadata: Map<string, unknown> | undefined) {
8+
this.id = id;
9+
this.data = data;
10+
this.metadata = metadata;
11+
this.adjacentVertices = new Map<string, Vertex<T>>();
12+
}
13+
14+
addAdjacentVertex(vertex: Vertex<T>) {
15+
if (!this.adjacentVertices.has(vertex.id)) {
16+
// add adjacent vertex given ID, if this vertex does not exist
17+
this.adjacentVertices.set(vertex.id, vertex);
18+
19+
// add this vertex as a neighbour
20+
vertex.addAdjacentVertex(this);
21+
}
22+
}
23+
}

datastructures/Graphs/devbook.js

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)