Linked list of related knowledge to organize what is linked list
A linked list is a non-sequential, non-sequential storage structure on a physical storage unit, and the logical order of the data elements is achieved through the order of the pointers in the linked list. A linked list consists of a series of nodes (each element in the list is called a node) that can be dynamically generated at run time. Each node consists of two parts: one is the data field that stores the data element, and the other is the pointer field that stores the next node address.
The difference between a linked list and an array
Recalling the concept of an array, the so-called array, is a set of elements of the same data type arranged in a certain order. According to the concept we can know that the array is contiguous in memory, the list is discontinuous, because different storage methods cause the array to statically allocate memory, the list dynamically allocates memory, the array element is in the stack area, the list element is in the heap area, because the array is contiguous in memory, we can use subscript to locate, time complexity is O (1), The list locates elements time complexity O (n), but because of the array's continuity array inserts or deletes elements of time complexity O (n), the time Complexity O (1) of the linked list. To summarize, the difference between an array and a linked list is as follows
1. Array statically allocates memory, the list dynamically allocates memory
2. The array is contiguous in memory, the list is discontinuous
3. Array elements in the stack area, linked list elements in the heap area
4. Array using subscript positioning, time complexity of O (1), linked list positioning element time complexity O (n);
5. The time complexity of an array to insert or delete elements O (n), the time Complexity O (1) of the linked list.
C # implements the basic operation of a linked list
In the case of a single linked list, we first define the data structure of the linked list node according to the definition of the list.
The difference between an array and a linked list