package wektoryzacja; import java.util.ArrayList; import java.util.List; public class Graf { private List n; private List> e; public Graf() { this.n = new ArrayList(); this.e = new ArrayList>(); } private int znajdzWierzcholek(int[] u) { for (int i = 0; i < this.n.size(); i++) { int[] w = this.n.get(i); if ((w[0] == u[0])&&(w[1] == u[1])) { return i; } } return -1; } public void dodajWierzcholek(int[] u) { if (this.znajdzWierzcholek(u) >= 0) { return; } this.n.add(u); this.e.add(new ArrayList()); } public int[] N(int i) { return this.n.get(i); } public List pobierzWierzcholki() { return this.n; } public void dodajKrawedz(int[] u, int[] v) { int nu = this.znajdzWierzcholek(u); if (nu < 0) { return; } int nv = this.znajdzWierzcholek(v); if (nv < 0) { return; } List eu = this.e.get(nu); if (!eu.contains(nv)) { eu.add(nv); } List ev = this.e.get(nv); if (!ev.contains(nu)) { ev.add(nu); } } public List E(int[] u) { int nu = this.znajdzWierzcholek(u); if (nu < 0) { return null; } return this.e.get(nu); } public boolean NEqual(int[] u, int[] v) { return (u[0] == v[0])&&(u[1] == v[1]); } }