Writing something is always good for yourself and proves that you are still trying to learn.
Daily accumulation is always good for yourself. Let's summarize our common data structure today.
1. Sequential table storage structure (typical array)
Principle: Sequential table storage is to put data elements into a contiguous memory storage space, access efficiency, fast. However, you cannot dynamically increase the length.
Advantages: Efficient access, direct storage via subscript.
Cons: 1. Insert and delete are slow, 2. Length cannot be increased.
For example: when inserting or deleting an element, the entire table needs to traverse the moving elements to rearrange the order.
Time performance: Find O (1), insert and delete O (n).
2. Linked list storage structure
principle: The chain table storage is the dynamic allocation space in the process of running the program, as long as the memory has space, there will be no storage overflow problem.
Advantages: Fast insertion and deletion, preserving the original physical order, such as inserting or deleting an element, just change the pointer to point.
Cons: Lookup is slow because finding an element requires one node from the start node to find the element access.
Time performance: Find O (n), insert and delete O (1).
1. from their storage advantages and disadvantages, each has its own usage scenarios, such as: frequent lookups but few insert and delete operations can be stored in the sequential table, if frequent insertions and deletions of small queries can use the linked list storage.
2. When the number of elements in a linear table varies greatly or is not known at all, it is best to use a single-linked list structure, so that you do not have to consider the size of the storage space problem. If you know in advance the approximate length of the linear table, such as December 1, a week is Monday to Sunday a total of seven days, this order structure efficiency will be much higher.
Note: Subsequent Java code will follow. Hope to be helpful to everyone.
I understand the sequential table and the linked list store