当前位置:网站首页>Linked list -------------------------- tail insertion method
Linked list -------------------------- tail insertion method
2022-07-29 06:18:00 【Plum juice】
First, create an instance of the linked list , Used to pass in values
ListNode temp1 = new ListNode(value);
First, determine whether there is a header node If not , The first value is the head node
if(head==null) {head = temp1; return;}
If head Of next It's empty.
ListNode temp2 = head;
temp2.next =temp1;
If headnext Not empty
while(temp2.next!=null) {
temp2 = temp2.next;
}
All code diagrams
ListNode:
public class ListNode {
int value;
ListNode next;// The address field of the next object
public ListNode(int value){
this.value = value;
}
@Override
public String toString() {
return "ListNode [value=" + value + ", next=" + next + "]";
}
}Test:
public class Test {
public static void main(String[] args) {
LinkList linkList = new LinkList();
linkList.insert(1);
linkList.insert(2);
linkList.insert(3);
linkList.insert(4);
linkList.insert(5);
System.out.println(linkList.head);
}
}
public class LinkList {
public ListNode head ;
public void insert(int value) {
ListNode temp1 = new ListNode(value);
if(head==null) {
head = temp1;
return;
}
ListNode temp2 = head;
while(temp2.next!=null) {
temp2 = temp2.next;
}
temp2.next = temp1;
}
}
=
边栏推荐
猜你喜欢
随机推荐
关于时间复杂度的个人看法
网络爬虫
【RoboMaster】从零开始控制RM电机(2)-CAN通信原理及电调通信协议
HAL库学习笔记- 8 串口通信之使用
Zero basics FPGA (5): counter of sequential logic circuit design (with introduction to breathing lamp experiment and simple combinational logic design)
JUC并发知识点
低功耗蓝牙5.0芯片nrf52832-QFAA
JUC集合类不安全
Dust and noise monitoring system
三国演义章节内容
唯美girls
噪声传感器工作原理是什么?
FPGA based: multi-target motion detection (hand-in-hand teaching ①)
Hal library learning notes - 9 DMA
TB6600+stm32F407测试
2022暑初二信息竞赛学习成果分享2
一些工具,插件,软件链接分享给大家~
智慧能源管理系统解决方案
Hal library learning notes-10 overview of Hal library peripheral driver framework
关于【链式前向星】的自学理解









