Java資料結構 鍊錶

2021-08-02 02:10:12 字數 1676 閱讀 6752

博主q q 656358805,歡迎線上交流!

public class mylinklist

public void addnode(type data)  //預設在鍊錶最後新增乙個結點

addindex.next=temp;

temp.pre=addindex;

this.size++;

system.out.println("成功插入乙個節點,鍊錶長度更改為: "+this.size);

}public void addnodewithindex(int index,type data)// 在指定的位置新增乙個結點

elseelse

if(addindex.next!=null)else} }

}public void deletenode()     //預設在鍊錶最後刪除乙個結點

system.out.println("預刪除的資料為: "+deleteindex.data);

deleteindex.pre.next=null;

deleteindex.pre=null;

deleteindex=null;

this.size--;

system.out.println("成功刪除乙個節點,鍊錶長度更改為: "+this.size);

}public void deletenodewithindex(int index)// 刪除指定位置的結點

else

if(deleteindex.next!=null)else}}

public int ishascontent(type data) //檢視鍊錶中是否有某個資料,如果有返回個數,沒有則返回0

}else

}if(count==0)else

return count;

}public void deletenodewithcontentcore(type data) //deletenodewithcontent函式的核心部分

}else}}

public void deletenodewithcontent(type data)//刪除鍊錶中某個指定資料的結點

}public void displaynodebyindex(int index)//顯示指定的結點資訊

else

system.out.println(index+"號結點的資料值為: "+displayindex.data);

system.out.println(index+"號結點的預備資料值為: "+displayindex.foreseedata);}}

public void displaynodebycontent(type data)//顯示指定內容的結點資訊}}

public void displayall()//顯示所有結點資訊

else

system.out.println(this.getname()+"的所有資料顯示完畢。");}}

public int getsize()

public string getname()

public void displayname()

public void setname(string name)

private class node  

public node(type data)    //結點構造  }

}

資料結構 Java鍊錶

package linktest class link 遞迴新增節點到尾部 param newnode public void addnode node newnode else 以上為內部類 private node root 定義根節點 呼叫內部類方法新增節點 param data public...

資料結構 鍊錶 JAVA版

和c 並沒有差別不大,主要是指標改為了引用變數,其他的鏈式結構基本可以參照這個 至於樹的話注意下遞迴就大致可以了 package com.sun.study.test class link public void display class linklist public boolean isemp...

java資料結構 雙向鍊錶

鍊錶是非常常見的一類線性結構的資料結構,每個節點包含有指標域和資料域,常見的包括單項列表 雙向列表 迴圈列表。這篇文章將詳細介紹雙向鍊錶。本文將介紹雙向鍊錶的插入節點 根據位置插入節點 刪除頭結點 刪除尾節點 刪除指定位置節點,檢視鍊錶元素 檢視頭結點 檢視尾節點 檢視鍊錶長度 判斷鍊錶是否為空。鍊...