Created
December 1, 2012 06:03
-
-
Save jeewamp/4180750 to your computer and use it in GitHub Desktop.
Check the graph is Eulerian, Semi-Eulerian or Non-Eulerian.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @param adjacencyList of the graph | |
| * @return ArrayList of oddVertices. if oddVertices is empty its Eulerian, | |
| * if it has 2 elements its Semi-Eulerian, else its not Eulerian. | |
| */ | |
| public <P extends Integer, Q extends ArrayList<P>> ArrayList<P> checkEulerian(HashMap<P, Q> adjacencyList) { | |
| ArrayList<P> oddVertices = new ArrayList<P>(); | |
| Iterator iterator = adjacencyList.keySet().iterator(); | |
| while(iterator.hasNext()) { | |
| P key = (P) iterator.next(); | |
| int checkEven=adjacencyList.get(key).size()%2; | |
| if(checkEven!=0) { | |
| oddVertices.add(key); | |
| } | |
| } | |
| return oddVertices; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment