First acquainted with the Java language-sequence table and singly linked list (basic knowledge 1-create a linear list)

First acquainted with the Java language-linear table (basic knowledge 1-create a linear table)

In the data structure, the data structure is logically divided into a linear table and a non-linear table, and the linear table is divided into a sequential table and a linked list according to whether the storage unit is continuous.
1.
Sequence table You can regard the sequence table as an array because its storage units are continuous. To access its elements, you need to know the first address and offset, and then you can randomly access the values ​​in the sequence table. Let's take a look at how to create a sequence table. (The algorithm in the following table is supplemented in the following order)

class ArraysList{
    
    
private int usedSize;
private int[]num;
public ArraysList(){
    
    
this.num=new int[5];
}
}
public class Main{
    
    
ArraysList arr=new ArraysList();//此时就算创建了一个存储长度为5的一个顺序表了
}

But the downside of the sequence table is that when I perform a delete or insert operation, a large number of elements will be moved, and if the sequence table is expanded, if we only need to add one more element, then there will be more storage space. It will be wasted, so the linked list is derived.
2.
The nature of the linked list and the sequence list are completely opposite (the storage structure is not continuous, will never fill up, and does not waste space, but it must be able to randomly access data elements, and everything is operated on the premise of traversing the entire linked list. Yes. Let’s take a look at how to create a single necklace watch.
Insert picture description here
Insert picture description here

class Node{
    
    
public int data;
public Node next;
public Node(){
    
    
}
public Node(int data){
    
    
this.data=data;
}
}
//暂时以头插法创建一个单链表,后序会补充尾插和其他功能
public class LinkList{
    
    
Node head;
public creatLink(int data){
    
    
Node node=new Node(data);
node.next=this.head;
this.head=node;
}
}
public class Main{
    
    
public static void main(String[]args){
    
    
LinkList link=new LinkList();
link.creatLink(8);
link.creatLink(7);
link.creatLink(6);
}//这样就创建了一个单向链表,6 7 8
}

The above is the creation of the sequence table and the singly linked list. The subsequent sequence will supplement some algorithms of the sequence table and the linked list. Come on! ! ! ! !

Guess you like

Origin blog.csdn.net/qq_45841205/article/details/112060380