BFS code is not working

public boolean bfs(String src,String dst) {
HashMap<String, Boolean> processed = new HashMap<>();
LinkedList queue = new LinkedList();
//creat new pair
Pair sp = new Pair();
sp.vname =src;
sp.psf =src;
//put the new pair in queue
queue.addLast(sp);
//while queue is not empty keep on doing the work
while(!queue.isEmpty()) {
//remove a pair from the queue
Pair rp = queue.removeFirst();
//if vertex alerady visited then skip
if (processed.containsKey(rp)) {
break;
}
//processed putting
processed.put(rp.vname,true);
//is there any direct edge?
if(containsEdges(rp.vname, dst)) {
return true;
}
//nbrs
Vertex rpvtx = Vtces.get(rp.vname);
ArrayList naibors = new ArrayList<>(rpvtx.nbrs.keySet());
for(String nbr: naibors) {
//processed only unprocessed naughbers
if(!processed.containsKey(nbr)) {
//make a new pair of naughbers
Pair np =new Pair();
np.vname =nbr;
np.psf =rp.psf+nbr;
//put new naughbers in queue
queue.addLast(rp);
}
}
}
return false;
}

Hey @abdullahalnomancse_f85bf5e5dcddaf61 Here you have to use a generic linkedlist which will store Pairs. To do that you have to change LinkedList queue = new LinkedList();
to
LinkedList queue = new LinkedList<>();

i think its not the problem…

@abdullahalnomancse_f85bf5e5dcddaf61 I found one more problem in this
if (processed.containsKey(rp)) {
break;
}
you have to check rp.vname is present in map or not(You have checked rp) and if it is present then you have to move to next iteration so instead of break you have to use continue; statement.

kindly check the full code sir

@abdullahalnomancse_f85bf5e5dcddaf61 I have edited my reply please go through it.

yes sir thank you … but it was not the problem as well. i found the problem.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.