Difference between array and list

What is the difference between an array and a list?

+3
source share
6 answers

In C, an array is a fixed-size area of ​​continuous storage that contains several objects, one after another. This array is an “object” in the meaning that C gives the word - basically just some memory that represents something. An object can only be int.

You can distinguish between array objects and array types a little. Often people use array objects that are allocated with malloc, and are used with a pointer to the first element. But C also has specific types for arrays of different sizes, as well as for variable-length arrays, the size of which is set when they are created. VLAs have a slightly misleading name: size is only a "variable" in the sense that it is not fixed at compile time. It cannot change throughout the entire life cycle of an object.

, , , , , VLA. realloc, , , , , . realloc , .

. C , . -, , -, ;-) "" , .

"" , , - .

C , " ?", :

+4

C list, .

: , .
: , .

, Python, list array, .

:

. , , , 1/4. O (1) , , () . - lasseespeholt

Python list . Python list array list , (int, float ..). - KennyTM

+5

C. ++ , . ++ , .

, - O(1) (.. a , a[4]) , - , (.. b , 5- b, 0, 1, 2, 3 4), .

+5
  • , , new int [100] ...

  • , : , shiftRight shiftLeft

  • Linked List node, node ; , . - , node ( ), node ( ).

  • node - header.prev, ( ). .

  • , Linked List.

,

!

O (n) O (1),

, ,

! , . , .

,

.

, !:)

+1

, , - . , 100 , 10 . 10 , , , , , , node.

0

an array has only similar data types (i.e.), they are uniform in nature. we can only have an array of strings, integers, etc., and also the size of the array is predetermined. but in the case of a list, we can have any types of elements. let it be an integer or a combination of both. Also, null or duplicate elements are allowed in the list. An example list includes arraylist, linkedlist.here in the list the size can increase or decrease at any time.

0
source

Source: https://habr.com/ru/post/1759739/


All Articles