📄 run1.java
字号:
/**
*
*/
package run;
import java.util.List;
import java.util.Scanner;
import digraph.Graph;
import digraph.Node;
/**
* @author zhangli
*
*/
public class Run1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
DataParser reader = new DataParser();
Graph graph = reader.readGraph("data/wikipedia.idx");
System.out.println("Load Success!! Please enter command:");
Scanner stdin = new Scanner(System.in);
while (stdin.hasNext())
{
String command = stdin.next();
if (command.equals("hasEdge"))
{
String name1 = stdin.next();
String name2 = stdin.next();
Node node1 = graph.getNode(name1);
Node node2 = graph.getNode(name2);
if (node1 == null || node2 == null)
{
System.out.println("No");
continue;
}
if (graph.hasEdge(node1, node2))
System.out.println("Yes");
else
System.out.println("No");
}
else if (command.equals("getSuccessors"))
{
String name = stdin.next();
Node node = graph.getNode(name);
if (node == null)
{
System.out.println("No such node");
continue;
}
System.out.printf("Successor of Node %s:", node.getName());
printList(graph.getSuccessors(node));
}
else if (command.equals("getPredecessors"))
{
String name = stdin.next();
Node node = graph.getNode(name);
if (node == null)
{
System.out.println("No such node");
continue;
}
System.out.printf("Predecessor of Node %s:", node.getName());
printList(graph.getPredecessors(node));
}
}
}
private static void printList(List list) {
// TODO Auto-generated method stub
if (list.size() == 0)
{
System.out.println("[None]");
return;
}
for (Object o : list)
{
Node node = (Node)o;
System.out.print(node.getName()+" ");
}
System.out.println();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -