-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathGraphGenericExample.java
More file actions
41 lines (30 loc) · 949 Bytes
/
GraphGenericExample.java
File metadata and controls
41 lines (30 loc) · 949 Bytes
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
package Graphs;
import java.util.Date;
class User { // This is how social media connection is made
String name;
long uid;
public User(String name, long uid) {
this.name = name;
this.uid = uid;
}
@Override
public String toString() {
return this.name;
}
}
public class GraphGenericExample {
public static void main(String[] args) {
GraphGeneric<User> graph = new GraphGeneric<>(false);
User one = new User("Nisab", 05157435);
User two = new User("Rahul", 65757567);
User three = new User("James", 57576757);
User four = new User("Tylor", 7575758);
// Adding edge basically means making friends
graph.addEdge(one, two);
graph.addEdge(two, three);
graph.addEdge(three, four);
System.out.println(graph);
// returns friends circle of just nisab
System.out.println(graph.dfs(one));
}
}