Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- static final int MSIZE = 6;
- public static void main(String[] args) {
- // READ IN ADJACENCY MATRIX FROM FILE
- // CALL checkBipartite(matrix);
- }
- private static boolean checkBipartite(int[][] adjMatrix) {
- for i=0 to MSIZE
- for j=0 to MSIZE
- if we have not been to the vertex
- add i to red list;
- vertexRed = true;
- else
- determine if vertex is red or blue and set vertexRed or vertexBlue
- if vertexRed == true
- if j is in blue list
- continue
- else if j is in red set
- ERROR, NOT BIPARTITE
- else
- add j to blue set because i is red
- if vertexBlue == true
- if j is in red list
- continue
- else if j is in blue list
- ERROR, NOT BIPARTITE
- else
- add j to red set because i is blue
- // reset red and blue flags on each new column
- vertexRed = false;
- vertexBlue = false;
- }
- if(bipartite) {
- printPartitions(redSet, blueSet);
- }else {
- System.out.println("This graph is not bipartite, see problem vertices above");
- }
- return bipartite;
- }
- static void printPartitions(LinkedList<Integer> red, LinkedList<Integer> blue) {
- sysout("This graph is bipartite!")
- sysout("red set = ")
- for each in red set print
- sysout("blue set = ")
- for each in blue set print
- }
- }
Add Comment
Please, Sign In to add comment