-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.java
59 lines (49 loc) · 1.13 KB
/
Graph.java
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
import java.util.Scanner;
import java.util.ArrayList;
class Node{
String data;
ArrayList<String> connections = new ArrayList<String>();
Node(){
data = null;
}
Node(String data, ArrayList<String> connections){
this.data = data;
this.connections = connections;
}
static void connect(Node n1, Node n2){
n1.connections.add(n2.data);
n2.connections.add(n1.data);
}
void show(){
System.out.println(connections);
}
}
class Graph{
public static void main(String[] args){
Node n1 = new Node();
Node n2 = new Node();
n1.data = "a";
n2.data = "b";
Node.connect(n1,n2);
System.out.println(n1.connections);
// Scanner scan = new Scanner(System.in);
// System.out.println("Enter the number of vertices: ");
// int num = scan.nextInt();
//
// Node[] vertices = new Node[num];
//
// for (int i=0; i<num; i++){
// vertices[i] = new Node();
// vertices[i].data = Integer.toString(i);
// System.out.println("Enter connections of " + i + " vertex: ");
// String inp = scan.next();
// vertices[i].connect(inp);
// vertices[i].show();
//
// }
//
// for (int i; i<num;i++){
// vertices[i].
// }
// }
}