0

I am trying to vertex to 2 arraylist ( setA, setB) in which I am going to store vertices. Later on I am going to compare them using BFS and find the Maximam Size(Bipartite Graph) but i am stuck on getting the input.

here is what i have so far

import java.util.*;



public class BipartiteGraph {

    private String strName;
    ArrayList<Vertex>[] vertexList;

    public BipartiteGraph(){

        vertexList = new ArrayList[2];
        vertexList[0] = new ArrayList<Vertex>();
        vertexList[1] = new ArrayList<Vertex>();
    }

    public boolean setA(Vertex v1){
        vertexList[0].add(v1);
        return false;
    }

    public boolean setB(Vertex v2){
        vertexList[1].add(v2);
        return false;
    }  
}

class Vertex{
    public String name;   
    public List adj; 
    public Vertex next; 
    public Vertex(String nm){
        name = nm;
        adj = new LinkedList();
      }
}

class Edge{
    public Vertex vertA;   
    public Vertex vertB;  
    public Edge( Vertex destination, Vertex comesfrom ){
        vertA = comesfrom;
        vertB = destination;
    }

    public static void main(String[] args){
      Scanner vertexInput = new Scanner(System.in);
      BipartiteGraph g = new BipartiteGraph( );
      g.setA(vertexInput.nextBoolean()); <-- I get the error here and to resolve it I tried new Vertex(.....) but that did not work as well
    } 
}

How can i take the input correctly so that i can perform BFS search late. Also I need to use adjacency list. Can I use it with my current code later?

2
  • Didn't you ask this same question a few minutes ago? Commented Nov 24, 2013 at 22:05
  • Yes i did, but trying a different approach for it. Commented Nov 24, 2013 at 22:06

1 Answer 1

0
g.setA(vertexInput.nextBoolean());

You're trying to call method setA(Vertex v1) with an argument of boolean type since Scanner.nextBoolean() returns boolean (as the name suggests).

Even if you try to call this method like

g.setA(new Vertex(String));

then you still cannot use nextBoolean() since Vertex constructor accepts only String argument. Try using g.setA(new Vertex(vertexInput.nextLine()));

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.