Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Graph {
- int numberOfVertices;
- ArrayList<Integer>[] adjacencyList;
- public Graph(int numberOfVertices){
- this.numberOfVertices=numberOfVertices;
- adjacencyList=new ArrayList[numberOfVertices];
- for(int i=0;i<numberOfVertices;i++)
- adjacencyList[i]=new ArrayList<>();
- }
- public void addEdge(int x,int y){
- adjacencyList[x].add(y);
- }
- public ArrayList<Integer> getAdjacentVertices(int x){
- return adjacencyList[x];
- }
- public boolean hasEdge(int x,int y){
- return adjacencyList[x].contains(y);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement