所以我想做的是找到一种方法来更改该程序的确切功能,但使用我的自定义 LinkedList 类而不是 Java LinkedList 库。因此,我没有导入 LinkedList,而是使用我制作的类。问题是我在实现这一点时遇到了很多麻烦。我想知道是否有任何关于如何执行此操作的提示或任何解决方案?
提前致谢。
主要的:
File f = new File("ass3.txt");
Scanner scan = new Scanner(f);
if (f.exists() == false) {
System.out.println("File doesn't exist or could not be found.");
System.exit(0);
}
int nVertices = scan.nextInt();
int nEdges = scan.nextInt();
for (int i = 0; i < 21; i++) {
String s = scan.nextLine();
}
int[] dong = new int[99];
Graph graph = new Graph(nVertices);
for (int i = 0; i < 99; i++) {
String vertex = scan.next();
String connected = scan.next();
int weight = scan.nextInt();
dong[i] = weight;
graph.addEdge(Graph.convertInt(vertex), Graph.convertInt(connected));
}
String startPoint = scan.next();
String finishPoint = scan.next();
graph.printGraph1(dong);
LinkedList1(我想使用我的自定义类而不是导入 LinkedList):
static class LinkedList1 {
Node head;
static class Node {
static int data;
Node next;
Node(int d) {
data = d;
}
}
public LinkedList1 insert(LinkedList1 list, int data) {
Node new_node = new Node(data);
new_node.next = null;
if (list.head == null) {
list.head = new_node;
} else {
Node last = list.head;
while (last.next != null) {
last = last.next;
}
last.next = new_node;
}
return list;
}
public void printList(LinkedList1 list) {
Node currNode = list.head;
System.out.print("LinkedList: ");
while (currNode != null) {
System.out.print(currNode.data + " ");
currNode = currNode.next;
}
}
@Override
public String toString() {
return "Data: " + Node.data;
}
}
幕布斯7119047
相关分类