-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraphSample.java
More file actions
34 lines (33 loc) · 837 Bytes
/
GraphSample.java
File metadata and controls
34 lines (33 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
public class GraphSample{
public static int degree(Graph G,int V){
int degree=0;
for (int w:G.adj(V)) degree++;
return degree;
}
public static int maxDegree(Graph G){
int max=0;
for (int V=0;V<G.V();V++){
if (degree(G,V)>max) max=degree(G,V);
}
return max;
}
public static int SelfLoops(Graph G){
int count=0;
for (int V=0;V<G.V();V++){
for (int w:G.adj(V)){
if (w==V) count++;
}
}
return count;
}
public String toString(){
String s=V+"vertices"+E+"edges\n";
for (int v=0;v<V;v++){
s+=v+":";
for (int w:this.adj(v)){
s+=w+"";
}
s+="\n";
}
}
}