当前位置:网站首页>LinkedList set
LinkedList set
2022-07-03 08:27:00 【bai259257】
package List;
import java.util.LinkedList;
public class LinkedListDemo02 {
public static void main(String[] args) {
//linkedList Sets inherit from List aggregate , Its underlying data structure is a two-way linked list ,ArrayList There are no unique methods in the collection , It has some unique methods ( Chicken ribs ), These special methods are specially used to operate the head and tail nodes
// A one-way linked list consists of nodes one by one . Each node has two areas , Pointer field and content field , The pointer field defaults to ^, If the next element has content , Then store the address value of the next element ; The content field stores the content of the current element
// characteristic : Additions and deletions quickly , Slow query
// Because it's an unordered list , So add elements directly to the memory space , Let the pointer field in the original set point to the address of the added element ,
// Remove elements , Directly find the element corresponding to the index , The pointer field in the deleted element stores the address value of the next element and gives it to its previous element , That is, let the pointer field of the upper element point to the pointer field of the lower element .
// The query is slow because , His nodes are stored randomly . Query elements can only be searched backwards from the first node , Until we find it . The storage of arrays in space is continuous , So the query is faster
// The two-way linked list has three areas , Forefinger needle field 、 Data fields 、 Back pointer field .
// The advantages of a two-way linked list over a one-way linked list are : It can find elements from the beginning of the node , You can also find from the tail node , You can query from which side the element is close , This improves the query ability in disguise
// shortcoming 1: When deleting elements , One way linked list only needs to notify the previous node , Now you need to notify the previous node and the next node , So the addition and deletion will be slower than the one-way linked list
// shortcoming 2: Because each node in the bidirectional linked list stores three areas , So it will occupy more memory
System.out.println("==================== Unique method =====================");
// Reason why linkedList The unique methods in the set compare chicken ribs , Because it is inherited from List and Collection All methods can realize these functions , Of course, developers are not cerebral palsy , These methods will run faster
LinkedList<String> strList = new LinkedList<>();
strList.add(" Liu Xuande ");
strList.add(" Zhang Yide ");
strList.add(" Guan Yunchang ");
strList.add(" Cao mengde ");
strList.add(" Sun Zhongmou ");
// A unique method to obtain the head node and tail node
//public E getFirst() : Get the header element
System.out.println(" Head node :" + strList.getFirst()); // replace :get(0);
//public E getLast() : Get the tail node element
System.out.println(" Caudal node :" + strList.getLast()); // Replace :get(strList.size() - 1);
// The unique method of adding head nodes and tail nodes
//public void addFirst(E e) : Add a new header node element
strList.addFirst(" Zhuge Kongming "); // replace :add(0," Zhuge Kongming ")
//public void addLast(E e) : Add tail node element
strList.addLast(" Sima yi "); // Replace :add(" Sima yi ");
System.out.println(" The content of the set after adding the head and tail nodes is :" + strList);
// A unique method of deleting head and tail nodes
//public E removeFirst() : Delete header node ( Returns the deleted element )
strList.removeFirst(); // replace :remove(0)
//public E removeLast() : Delete tail node ( Returns the deleted element )
strList.removeLast(); // replace :remove(strList.size() - 1)
System.out.println(" After deleting the head and tail nodes, the content of the collection is :" + strList);
// Pop up the first element ( eject : Get and delete ) Unique method
String popElement = strList.pop();
System.out.println(" The element that pops up is :" + popElement);
System.out.println(" The set content after the pop-up element is :" + strList);
}
}
边栏推荐
- [linear table] basic operation of bidirectional linked list specify node exchange
- Puhua PLM empowers the whole scene product lifecycle management and helps the enterprise digital transformation of the main line of products
- Markdown directory generation
- Scite change background color
- ArrayList
- Golang time format sorting
- Simply start with the essence and principle of SOM neural network
- Youyou1 of xlua knapsack system
- Gradle's method of dynamically modifying APK package name
- Explain sizeof, strlen, pointer, array and other combination questions in detail
猜你喜欢
Three characteristics
Cloudcompare learning (1) - cloudcompare compilation and common plug-in implementation
基于SSM的校园失物招领平台,源码,数据库脚本,项目导入运行视频教程,论文撰写教程
Advanced OSG collision detection
Storage of data
Haproxy+kept build 01
Introduction to Base64 coding
数据的存储
VIM learning notes from introduction to silk skating
Jupyter remote server configuration and server startup
随机推荐
Un système de gestion de centre commercial pour la conception de cours de technologie d'application de base de données
Simple demo of solving BP neural network by gradient descent method
Unity editor expansion - scrolling list
redis集群系列四
Golang 字符串分割,替换和截取
MXone Pro自适应2.0影视模板西瓜视频主题苹果cmsV10模板
E: Unable to locate package ROS melody desktop full
Classes and objects
【云原生】微服务之Feign的介绍与使用
Unity editor expansion - window, sub window, menu, right-click menu (context menu)
Visual Studio (VS) shortcut keys
P1596 [USACO10OCT]Lake Counting S
swagger文档配置
十六进制编码简介
MySQL containerization (1) docker installation MySQL
796 · unlock
Basic operation and process control 2
数据的存储
二进制转十进制,十进制转二进制
Thymeleaf 404 reports an error: there was unexpected error (type=not found, status=404)