Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lab03;
- /**
- *
- * @author Nan Mihai
- */
- public class Graph {
- private boolean mat[][];
- private int nr;
- public Graph(int nr) {
- this.nr = nr;
- this.mat = new boolean[nr][nr];
- }
- public int size() {
- Graph g = this;
- return g.nr;
- }
- public void addArc(int v, int w) {
- Graph g = this;
- g.mat[v][w] = true;
- }
- public boolean isArc(int v, int w) {
- return this.mat[v][w];
- }
- public void print() {
- Graph g = this;
- for(int i = 0; i < g.nr; i++) {
- for(int j = 0; j < g.nr; j++) {
- if(g.mat[i][j] == true){
- System.out.print("1 ");
- } else {
- System.out.print("0 ");
- }
- }
- System.out.println();
- }
- }
- public void dfs(int v, boolean vazut[]) {
- int w;
- vazut[v] = true;
- for(w = 0; w < this.nr; w++) {
- if(isArc(v, w) && !vazut[w]) {
- System.out.println(v + " - " + w);
- dfs(w, vazut);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment