單向鍊錶(借鑑)

2021-09-24 06:23:09 字數 1211 閱讀 4079

下圖表示一種單向列表。其中指標first指向隊頭,last指向隊尾,curr指向當前讀的資料。

下面是我的實現**,很簡單,明白上述結構後,關鍵是構造乙個內部類,裡面包含乙個指向下乙個元素的物件(指向下乙個元素的指標)

package cn.xy.linkedlist;

public class mylinkedlist

/*** 往煉表中新增資料(隊尾新增資料)

*/public t add(t element)

size++;

return element;

} /**

* 移除鍊錶中的資料(隊頭移除)

*/public t remove()

t result = first.element;

first = first.next;

currread = first;

size--;

return result;

} /**

* 獲取佇列中的元素

*/public t get()

t result = currread.element;

currread = currread.next;

return result;

} /**

* 再次從頭開始讀取資料

*/public void setreadagain()

public string tostring()

return sb.tostring();

} /**

* 獲取佇列大小 《功能詳細描述》

*/public int getsize()

class node

}}

package cn.xy.linkedlist;

public class test1

system.out.println(linkedlist.tostring());

for(int i=0;i<5;i++)

system.out.println(linkedlist.tostring());

system.out.println("-------end-------");

}}

單向鍊錶(還沒有借鑑其他的實現方法)

單向鍊錶的5個操作 建立,輸出,刪除,在第i個點後加入新點,刪除第i個點,編譯環境是codeblocks include include struct node node creatlist int n return head void print node head printf n void d...

鍊錶 反轉單向鍊錶

思路 從第二個元素開始。1 刪除當前元素。2 把當前元素放到頭結點位置。其中需要宣告3個變數 headnode 頭結點 prenode 前乙個結點 currentnode 當前結點 具體步驟如圖所示 實現 反轉單鏈表方法實現類 created by liujinjin on 17 1 19.publ...

鍊錶1 單向鍊錶

鍊錶中最簡單的一種是單向鍊錶,它包含兩個域,乙個資料域和乙個指標域,指標域指向鍊錶中的下乙個節點,最後乙個節點的指標域指向乙個空值 鍊錶最基本的結構是在每個節點儲存資料和到下乙個節點的位址,在最後乙個節點儲存乙個特殊的結束標記,另外在乙個固定的位置儲存指向第乙個節點的指標,有的時候也會同時儲存指向最...