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
| package com;
public class Graph {
private final int nodeLength; private int lineLength; private Queue<Integer>[] adj;
Graph(int nodeLength) { this.nodeLength = nodeLength; this.lineLength = 0; this.adj = new Queue[nodeLength]; for (int i = 0; i < adj.length; i++) { adj[i] = new Queue<Integer>(); } }
public int getNodeLength() { return nodeLength; }
public int getLineLength() { return lineLength; }
public void addEdge(int node1, int node2) { adj[node1].enQueue(node2); adj[node2].enQueue(node1); lineLength++; }
public Queue<Integer> adj(int node) { return adj[node]; }
}
|