Is out looking for a job, if you can’t very good and the interviewer used to talk about the inside of the Java based algorithm and data structure, basic is impossible, so we start we will give you a detailed talk about the relevant implementation from Java collection of data structures and algorithms involved in implementation, this paper first to introduce the most simple data structure, array and a linked list.

A, arrays,

Arrays are one of the simplest data structures we use, arrays

Char c1[] = new char[5]; char c1[] = new char[5] Char c2[] = new char[]{'E','D','U','Y','U'}; char char[]{'E','D','U','Y','U'}; char c3[] = {'E','D','U','Y','U'};Copy the code

It has the following characteristics:

  • Memory address contiguous,
  • Can be accessed through the subscript member, subscript access performance is high
  • Add and delete operations cause greater performance consumption (dynamic capacity expansion is required to ensure that data is out of bounds)

Second, the linked list

Linked lists also store data in linear order. A Pointer to the next node is stored on each node.

Unidirectional linked list

A unidirectional list (singly linked list) is a type of linked list. It consists of nodes, each of which contains a pointer to the next node. The following is a singly linked list.

Then let’s look at deleting a linked list, such as removing 30

Let’s add another node to the list based on the above structure

Bidirectional linked list

A bidirectional list (doubly linked list) is a type of linked list. Like a singly linked list, a double-linked list is made up of nodes, and each data node has two Pointers to direct successors and direct precursors. So, starting from any node in a bidirectional linked list, you can easily access its predecessors and successors. In general, we construct bidirectional circular lists.

A double-linked list looks like this:

The concrete implementation of bidirectional linked list can be referenced

Static final class Node {// Volatile Node prev; // Volatile Node next; // The specific data stored by the linked list node is volatile Thread Thread; }Copy the code

Let’s look at deleting a node from a two-way list. For example, in this single list, we want to delete “node 30”.

Before being deleted: The successor node of node 20 is node 30, and the predecessor node of node 30 is node 20. The successor of node 30 is node 40, and the predecessor of node 40 is node 30.

After deleting: The successor of Node 20 is node 40, and the predecessor of node 40 is node 20.

Let’s look at adding nodes to a bidirectional list. For example, in this bidirectional list, add “node 15″ between” node 10″ and “node 20”.

Before adding nodes: The successor node of node 10 is node 20, and the predecessor node of node 20 is node 10.

After the node is added: The successor node of node 10 is node 15, and the predecessor node of node 15 is node 10. The successor of node 15 is node 20, and the predecessor of node 20 is node 15.

Data and linked list content is relatively simple, we will introduce you here.

Three things to watch ❤️

If you find this article helpful, I’d like to invite you to do three small favors for me:

  1. Like, forward, have your “like and comment”, is the motivation of my creation.

  2. Follow the public account “Java rotten pigskin” and share original knowledge from time to time.

  3. [666] Scan the code to obtain the learning materials package

  4. Also look forward to the follow-up article ing🚀