Advertisement
informaticage

Indegree and outdegree

Feb 3rd, 2020
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.68 KB | None | 0 0
  1. public HashMap<Vertex, Integer> Indegree ( ) {
  2.         HashMap <Vertex, Integer> degrees = new HashMap <Vertex, Integer> ( );
  3.        
  4.         for ( Vertex v : this.adjacencyMap.keySet() )
  5.             degrees.put( v, 0 );
  6.        
  7.         for ( Vertex v : this.adjacencyMap.keySet() )
  8.             for ( Vertex inV : this.adjacencyMap.get( v ).keySet() )
  9.                 degrees.put( inV , degrees.get(inV) + 1 );
  10.        
  11.         return degrees;
  12. }
  13.  
  14. public HashMap<Vertex, Integer> Outdegree ( ) {
  15.         HashMap<Vertex, Integer> outDegrees = new HashMap<Vertex, Integer>( );
  16.        
  17.         for ( Vertex v : this.adjacencyMap.keySet() )
  18.             outDegrees.put( v, this.adjacencyMap.get(v).size() );
  19.        
  20.         return outDegrees;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement