亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從 LinkedList 庫更改為自定義類

從 LinkedList 庫更改為自定義類

肥皂起泡泡 2023-09-27 14:49:44
所以我想做的是找到一種方法來更改該程序的確切功能,但使用我的自定義 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;    }}
查看完整描述

1 回答

?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

如果您只是尋找一種方法來用LinkedList您的實例替換現有實例,則您需要:

  1. 從您的進口中刪除java.util.LinkedList。

  2. 使用完全限定的類名將您的類添加LinkedList1為導入,例如:xyz.abc.LinkedList1

  3. 將聲明: 替換LinkedList<Integer> list[]LinkedList1 list[],并將初始化:list[i] = new LinkedList<>()替換為list[i] = new LinkedList1()

  4. 將您使用的方法替換為LinkedList中的等效方法LinkedList1。

如果這就是您要找的,請告訴我。


查看完整回答
反對 回復 2023-09-27
  • 1 回答
  • 0 關注
  • 111 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號