0% found this document useful (0 votes)
4 views1 page

Adjacent

Uploaded by

laplace.beta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

Adjacent

Uploaded by

laplace.beta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import java.util.

ArrayList;

public class Adjacent {

public static void main(String[] args) {


ArrayList<ArrayList> adjList = new ArrayList<>();
char[] vertices = {'A','B','C','D','E','F','G'};
int num = 7;
for(int i=0;i<num;i++){
adjList.add(new ArrayList<>());
}
adjList.get(0).add('B');
adjList.get(1).add('A');
adjList.get(1).add('C');
adjList.get(2).add('B');
adjList.get(2).add('D');
adjList.get(2).add('E');
adjList.get(3).add('C');
adjList.get(3).add('E');
adjList.get(3).add('F');
adjList.get(3).add('G');
adjList.get(4).add('C');
adjList.get(4).add('D');
adjList.get(4).add('F');
adjList.get(5).add('E');
adjList.get(5).add('D');
adjList.get(6).add('D');

int p = 0;
for(int i=0;i<num;i++,p++){
System.out.println(vertices[p] + ": " + adjList.get(i));
}
}
}

You might also like