Jump to content

Array: Difference between revisions

10 bytes added ,  15 years ago
not a task; don't use {{header}}
m (lang link fixing)
(not a task; don't use {{header}})
Line 29:
In most programming languages, arrays are accessed by using the array brackets <tt>[</tt> and <tt>]</tt>, e.g. in <tt>A[i]</tt>, but exceptions exist, including [[Rexx]] which instead uses the dot operator <tt>.</tt>, such as in <tt>A.i</tt>; [[Fortran]], [[Ada]] and [[BASIC]] which use round parentheses <tt>A(i)</tt>, and in [[LISP|lisp]] dialects which use constructions like <tt>(ELT A n)</tt> for accessing and <tt>(SETA A n new_val)</tt> for setting (Interlisp) or <tt>(vector-ref A n)</tt> for accessing and <tt>(vector-set! A n new_val)</tt> for setting (Scheme). No bracket indexing occurs in [[J]], an array language; instead, the normal syntax of function creation and function calling applies.
 
==Computational metrics==
==[[C]]==
Access is O(1), appending is O(1), and insertion is O(n).
 
==Examples==
 
===[[C]]===
We wish to open a text file and compute letter frequency
 
Line 52 ⟶ 57:
}
 
===[[J]]===
The example task is the same: open a text file and compute letter frequency.
<br>Written in this array programming language, no loops are specified.
Line 65 ⟶ 70:
)
 
===[[OCaml]]===
same task, open a text file and compute letter frequency
 
Line 86 ⟶ 91:
Here is [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html the documentation] of the module Array. (there is also a [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Bigarray.html Bigarray module])
 
=={{header|=[[Pascal}}]]===
This defines an array suitable to hold a 64x64 truecolor image (i.e. red, green and blue RGB values all can go from 0 to 255) and then sets the color of a single pixel
<lang pascal>
Line 104 ⟶ 109:
</lang>
 
=={{header|=[[Python}}]]===
Example: open a text file and compute letter frequency.
<lang python>
Line 162 ⟶ 167:
 
Again eliminating all fussing with the details of converting letters into list indices.
 
==Computational metrics==
Access is O(1), appending is O(1), and insertion is O(n).
 
[[Category:Data Structures]]
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.