当前位置:网站首页>Dynamic changes based on arrays and nodes (addition, deletion, modification and query)
Dynamic changes based on arrays and nodes (addition, deletion, modification and query)
2022-07-16 07:03:00 【Lemon Ning】
First, let's talk about arrays ArrayList
Fixed array format : int[] arr=new int[10]; // The length is 10 Array of
Generally, when building an array, you need to construct a constant length size , If the array length is not enough in the later stage , You need to create an array to copy .
Array needs to be initialized .
Dynamic expansion array specific code :
// You need to define an array
public Object[] arr=new Object[8];
private int size;// The length of the array
// add to
public void add(E e){
// First, create an array
Object[] newarr=new Object[arr.length+1];
// Traversal
for (int i=0;i<arr.length;i++){
newarr[i]=arr[i];
}
newarr[arr.length]=e;
// Update the original array address
arr=newarr;
size++;
}
// Add to specific location For arrays , The functions of adding, deleting, changing and checking all need to traverse the data in the array before they can be replaced .
Linked list LinkList
List Attributes of a class :
- Storage container : Array
- length
- Subscript
List Class method :
- Additive elements :
- Add to the end
- Add to the last Find out When it is full, it needs to be expanded
- Remove elements :
- Delete the last one , The subscript needs to be modified
- Delete the element with the specified subscript , The following elements need to be moved forward
- Look for the element :
- Find by subscript
- Find by element
- Additive elements :
Specific implementation code :
Write a simple method
public void add(E e) {
Node newNode = new Node(e);// Newly established node
Node head = root.next;
if (head == null) {
head = newNode;
last = newNode;
} else {
last.next = newNode;
last = newNode;
}
size++;
}边栏推荐
- Use of rounding, rounding down, rounding up
- 002 pointers and functions
- Database dark horse notes DDL
- RT_ Thread critical zone protection
- Go秒杀系统3--Work模式,Publish模式
- How to select embedded single chip microcomputer?
- SSM整合(借鉴版)
- Go秒杀系统3--项目结构搭建,商品模型开发。
- Comparison and application of DHT11 and dht22 (am2302)
- ROS communication mechanism
猜你喜欢

RT_ Thread idle thread and two commonly used hook functions

多图详解阻塞队列——SynchronousQueue

IIC communication

LeetCode 刷题第十三天 + DL第三天

关于线程安全

VIM usage

Small stage summary

What can I do after learning C language? Let's make a push box first ~ (there are pictures)

LeetCode精讲——676. 实现一个魔法字典(难度:中等)

Chapter VI use of OLED module +stm32
随机推荐
LeetCode精講——676. 實現一個魔法字典(難度:中等)
桶排序+抽屉原理
DL第五天
Holiday study plan from June 24, 2022 to August 26, 2022
交易模块开发
AMD RDNA 3 Navi 31旗舰GPU据称采用3D V-Cache封装以及最高384MB缓存
LeetCode 第十五天
二叉树中的递归问题
[introduction to go language] 08 go language array
关于线程安全
【C语言】 大学生考勤管理系统
SSM integration (classic self version)
物联网学习之旅——初始
leetcode-3 无重复字符的最长字串(滑动窗口,unordered_set, st.find(string[i]))
LeetCode精讲——1252. 奇数值单元格的数目(难度:简单)
[introduction to go language] 03 go language data types, variables, constants
Leetcode-1 两数之和(STL, hashTable, unordered_map)
(一)OSI模型
DL第四天
股票买卖问题