Guest User

Untitled

a guest
Mar 22nd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. public class Main {
  2. static final int MSIZE = 6;
  3. public static void main(String[] args) {
  4.  
  5. // READ IN ADJACENCY MATRIX FROM FILE
  6. // CALL checkBipartite(matrix);
  7. }
  8.  
  9. private static boolean checkBipartite(int[][] adjMatrix) {
  10.  
  11. for i=0 to MSIZE
  12. for j=0 to MSIZE
  13. if we have not been to the vertex
  14. add i to red list;
  15. vertexRed = true;
  16. else
  17. determine if vertex is red or blue and set vertexRed or vertexBlue
  18.  
  19. if vertexRed == true
  20. if j is in blue list
  21. continue
  22. else if j is in red set
  23. ERROR, NOT BIPARTITE
  24. else
  25. add j to blue set because i is red
  26.  
  27. if vertexBlue == true
  28. if j is in red list
  29. continue
  30. else if j is in blue list
  31. ERROR, NOT BIPARTITE
  32. else
  33. add j to red set because i is blue
  34.  
  35. // reset red and blue flags on each new column
  36. vertexRed = false;
  37. vertexBlue = false;
  38. }
  39.  
  40. if(bipartite) {
  41. printPartitions(redSet, blueSet);
  42. }else {
  43. System.out.println("This graph is not bipartite, see problem vertices above");
  44. }
  45.  
  46. return bipartite;
  47. }
  48.  
  49. static void printPartitions(LinkedList<Integer> red, LinkedList<Integer> blue) {
  50. sysout("This graph is bipartite!")
  51. sysout("red set = ")
  52. for each in red set print
  53. sysout("blue set = ")
  54. for each in blue set print
  55. }
  56. }
Add Comment
Please, Sign In to add comment