I need to do this using a text file which contains a linked list of the graph which would be, (AEDB), (EA), (DA), (BAC), (CB), Then I ask the user for the node to start at and then the BFS order prints? I know one way to start would be to create a linked list then hash the linked list in a dictionary but don't know from there on, also a node can't be visited more than once. My linked list is something like, HashMap> L = new HashMap>();
LinkedList<String> listA = new LinkedList<String>();
listA.add("B");
listA.add("E");
L.put("A", listA);
LinkedList<String> listB = new LinkedList<String>();
listB.add("A");
listB.add("C");
listB.add("F");
L.put("B", listB);
LinkedList<String> listE = new LinkedList<String>();
listE.add("A");
listE.add("F");
L.put("E", listE);
LinkedList<String> listF = new LinkedList<String>();
listF.add("E");
listF.add("K");
listF.add("B");
L.put("F", listF);
LinkedList<String> listK = new LinkedList<String>();
listK.add("F");
listK.add("C");
L.put("K", listK);
LinkedList<String> listC = new LinkedList<String>();
listC.add("K");
listC.add("B");
L.put("C", listC);
The output would print the nodes starting from the user inputted one in a breadth first order, but this is as far as I have gotten
答案 0 :(得分:3)
您在此处使用的内容称为Adjacency list。
这是BFS的一个实现,它使用像你上面提到的那个template: '<div>BannerHeading - {{heading}}</div>'
并执行BFS。它在BFS遍历中打印访问的顶点。
adjacency list