package com.itguigu.linkarray;
//單鏈表
public class demo
}class singelonlinklist
//如果後面有資料,next指向下乙個域
temp = temp.next;
}//最後乙個物件,賦值給節點
temp.next = heronode;
}//顯示鍊錶
public void list()
//輔助節點遍歷
heronode temp=head.next;
while (true)
system.out.println(temp);
temp=temp.next;}}
//有序新增
public void addorder(heronode heronode)
if(heronode.numtemp=temp.next;
}if(flag)else
}public void update(heronode heronode)
heronode temp=head;
boolean flag=false;
while (true)
if(temp.num==heronode.num)
//往下遍歷
temp=temp.next;
}if(flag)else
}public void delete(heronode heronode)
//輔助指標
heronode temp=head;
boolean flag=false;
while (true)
//該節點的下一節點的編號等於要刪除的節點的編號
if(temp.next.num==heronode.num)
temp=temp.next;
}//找到要刪除的上乙個節點
if(flag)else
}}class heronode
@override
public string tostring() ';
}}
單鏈表的建立 新增 刪除操作
include include include typedef struct lnode lnode init the single linked list void init l struct lnode p linklist p while p q next null for i i 0 i i...
資料結構 單鏈表 新增 不按順序和按順序
2.1在新增英雄時,直接新增到鍊錶的尾部 思路分析 定義singlelinklist管理我們的英雄 class singlelinkedlist 如果沒有找到最後,將temp後移 temp temp.next 退出white迴圈時,temp就指向了鍊錶的最後 temp.next heronode 顯...
Python演算法 構建單鏈表,新增刪除元素
把鍊錶元素和鍊錶索引分別儲存在兩個list裡。listvalue 1,5,6,2,7,3 listright 3,2,4,5,1,1 元素新增時,要先讓新元素指標指向後面的元素,再讓他前面的元素指標指向新元素!不然,先讓前面的元素 a 指向新元素 b 再找新元素後面的元素 c 時,c的索引本來在a裡...