第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何訪問鏈表中每個節(jié)點的不同元素

如何訪問鏈表中每個節(jié)點的不同元素

慕姐4208626 2022-09-01 16:34:48
我有一個包含n個節(jié)點的鏈接列表,每個節(jié)點包含多個元素。我正在嘗試編寫一個允許我搜索節(jié)點的方法和另一個允許我在節(jié)點內(nèi)搜索元素的方法。我不知道我應(yīng)該如何訪問鏈表節(jié)點的內(nèi)部元素。所以我想我真正想知道的是,你如何引用/訪問每個單獨的元素與一個鏈表的節(jié)點?嘗試創(chuàng)建一個允許創(chuàng)建鏈接列表的程序,其中該鏈接列表中的節(jié)點數(shù)取決于用戶。該列表應(yīng)允許搜索節(jié)點和元素,并且還應(yīng)該進(jìn)行排序。    package nodelist;    public class NodeList {public int nodeid;public int nodestate;public int x_cord;public int y_cord;public int direction;public NodeList next;public NodeList(int nodeid, int nodestate, int x_cord, int y_cord, int direction){    this.nodeid = nodeid;    this.nodestate = nodestate;    this.x_cord = x_cord;    this.y_cord = y_cord;    this.direction = direction;}public void display(){    System.out.println("nodeid: "+nodeid + " state: " +nodestate+ " x: " +x_cord+ " y: " +y_cord+ " direction: " +direction);}//@Overridepublic String toString(){         return String.valueOf(this.nodeid); // Needed to convert int nodeid to string for printing}public static void main(String[] args) {    // TODO code application logic here    LinkList theLinkedList = new LinkList();        // Insert Link and add a reference to the book Link added just prior        // to the field next        System.out.println("Enter the number of nodes to deploy");                    int nodecount = 5;                    int nodeid = 5000;                    for(int i=0; i<nodecount;i++){                        theLinkedList.insertFirstLink(nodeid, 0,0,0,0);                        nodeid++;                    }                    /*        theLinkedList.insertFirstLink("5000", 0,0,0,0);        theLinkedList.insertFirstLink("5001", 1,1,1,1);        theLinkedList.insertFirstLink("5002", 2,2,2,2);        theLinkedList.insertFirstLink("5003", 3,3,3,3);        }
查看完整描述

2 回答

?
慕標(biāo)琳琳

TA貢獻(xiàn)1830條經(jīng)驗 獲得超9個贊

簡單地說,你可以做到這一點。將臨時節(jié)點指向頭節(jié)點,然后迭代溫度。

System.out.println(temp.your_element_name);


查看完整回答
反對 回復(fù) 2022-09-01
?
aluckdog

TA貢獻(xiàn)1847條經(jīng)驗 獲得超7個贊

僅當(dāng)節(jié)點列表中的元素數(shù)相同時,才能執(zhí)行此操作。作為單節(jié)點,請使用僅聲明一次的結(jié)構(gòu),因此它的內(nèi)存已經(jīng)確定。因此,您無法在運(yùn)行時增加節(jié)點的大小。下面我提到了C++代碼。


struct Node{

int list[5];

Node *node;

}


查看完整回答
反對 回復(fù) 2022-09-01
  • 2 回答
  • 0 關(guān)注
  • 88 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號