File tree Expand file tree Collapse file tree 1 file changed +19
-16
lines changed
Expand file tree Collapse file tree 1 file changed +19
-16
lines changed Original file line number Diff line number Diff line change 1- package Graph ;
1+ package
2+ Graph ;
23
34import java .util .LinkedList ;
45
5- public class Graph {
66
7- private final int V ;private int E ; private LinkedList <Integer >[] adj ;
7+ public class Graph {
8+
9+ private final int V ;private int E ;
10+ private LinkedList <Integer >[] adj ;
811
912 public Graph (int V )
1013 {
1114 this .V =V ;
1215 this .E =0 ;
13- adj = (LinkedList <Integer >[]) new LinkedList [V ];
14- for (int v = 0 ; v < V ; v ++)
15- adj [v ] = new LinkedList <>();
16+ adj = (LinkedList <Integer >[ ]) new LinkedList [ V ];
17+ for (int v =0 ; v < V ; v ++)
18+ adj [v ] = new LinkedList <>();
1619 }
1720
18- public int V ()
21+ public int V ( )
1922 {
2023
2124
@@ -25,24 +28,24 @@ public int V()
2528
2629 public
2730 int E () {
28- return E ;
31+ return E ;
2932 }
3033
3134 public void addEdge (int v , int w ) {
32- adj [v ].add (w );
33- adj [w ].add (v );
34- E ++ ;
35+ adj [v ].add ( w );
36+ adj [w ].add (v );
37+ E ++ ;
3538 }
3639
37- public LinkedList <Integer > adj (int v ) {
40+ public LinkedList < Integer > adj (int v ) {
3841 return adj [v ];
3942 }
4043
41- public int degree (int v ,Graph g ){
44+ public int degree ( int v ,Graph g ) {
4245 int count = 0 ;
43- for (int s : adj (v ))
46+ for (int s : adj (v ) )
4447 count ++;
45- return count ;
46- }
48+ return count ;
49+ }
4750
4851}
You can’t perform that action at this time.
0 commit comments