+ 2
Tell advantages of array
4 Antworten
+ 5
Imagine you hadn't: you should name every single variable you needed. For example: if you wanted to compute the average of, say, 20 numbers, you should name the variables like a, b, c, ... or a1, a2, a3... I'm sure you get the point. Plus, you couldn't add them up in a decent way. Compare sum = a1+a2+a3+... versus
sum=0
for i in range(0,20):
sum+=a[i]
(ok, it's Python, but it works quite alike in C++ or Java).
What if there was another variable, depending on the user's input? How could you name it, if you don't know if it's needed? With arrays, you simply append it.
+ 2
one variable, more than one values.
and the values of array it iteratable.
+ 1
versus what? list? linked list? dictionary? tree?..
+ 1
Answer is:-
* Easy to specify
* Free from run time overheads
* Simple code
* Fast sequential access