September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,20 +0,0 @@
|
|||
PROC array_test = VOID:
|
||||
(
|
||||
[1:20]INT a;
|
||||
a := others; # assign whole array #
|
||||
a[1] := -1; # assign individual element #
|
||||
a[3:5] := (2, 4, -1); # assign a slice #
|
||||
[1:3]INT slice = a[3:5]; # copy a slice #
|
||||
|
||||
REF []INT rslice = a[3:5]; # create a reference to a slice #
|
||||
print((LWB rslice, UPB slice)); # query the bounds of the slice #
|
||||
rslice := (2, 4, -1); # assign to the slice, modifying original array #
|
||||
|
||||
[1:3, 1:3]INT matrix; # create a two dimensional array #
|
||||
REF []INT hvector = matrix[2,]; # create a reference to a row #
|
||||
REF []INT vvector = matrix[,2]; # create a reference to a column #
|
||||
REF [,]INT block = matrix[1:2, 1:2]; # create a reference to an area of the array #
|
||||
|
||||
FLEX []CHAR string := "Hello, world!"; # create an array with variable bounds #
|
||||
string := "shorter" # flexible arrays automatically resize themselves on assignment #
|
||||
)
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
DEF ai[100] : ARRAY OF CHAR, -> static
|
||||
da: PTR TO CHAR,
|
||||
la: PTR TO CHAR
|
||||
|
||||
PROC main()
|
||||
da := New(100)
|
||||
-> or
|
||||
NEW la[100]
|
||||
IF da <> NIL
|
||||
ai[0] := da[0] -> first is 0
|
||||
ai[99] := da[99] -> last is "size"-1
|
||||
Dispose(da)
|
||||
ENDIF
|
||||
-> using NEW, we must specify the size even when
|
||||
-> "deallocating" the array
|
||||
IF la <> NIL THEN END la[100]
|
||||
ENDPROC
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
set empty to {}
|
||||
set ints to {1, 2, 3}
|
||||
|
|
@ -1 +0,0 @@
|
|||
set any to {1, "foo", 2.57, missing value, ints}
|
||||
18
Task/Arrays/ALGOL-W/arrays.alg
Normal file
18
Task/Arrays/ALGOL-W/arrays.alg
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
begin
|
||||
% declare an array %
|
||||
integer array a ( 1 :: 10 );
|
||||
% set the values %
|
||||
for i := 1 until 10 do a( i ) := i;
|
||||
% change the 3rd element %
|
||||
a( 3 ) := 27;
|
||||
% display the 4th element %
|
||||
write( a( 4 ) ); % would show 4 %
|
||||
% arrays with sizes not known at compile-time must be created in inner-blocks or procedures %
|
||||
begin
|
||||
integer array b ( a( 3 ) - 2 :: a( 3 ) ); % b has bounds 25 :: 27 %
|
||||
for i := a( 3 ) - 2 until a( 3 ) do b( i ) := i
|
||||
end
|
||||
% arrays cannot be part of records and cannot be returned by procecures though they can be passed %
|
||||
% as parameters to procedures %
|
||||
% multi-dimension arrays are supported %
|
||||
end.
|
||||
|
|
@ -1,9 +1,5 @@
|
|||
REDIM dynamicArray(10) AS INTEGER
|
||||
|
||||
dynamicArray(0) = -1
|
||||
PRINT dynamicArray(0)
|
||||
|
||||
REDIM dynamicArray(20)
|
||||
|
||||
dynamicArray(20) = 1
|
||||
PRINT dynamicArray(0), dynamicArray(20)
|
||||
10 DIM A%(11): REM ARRAY OF ELEVEN INTEGER ELEMENTS
|
||||
20 LET A%(1) = -1
|
||||
30 LET A%(11) = 1
|
||||
40 PRINT A%(1), A%(11)
|
||||
50 END
|
||||
|
|
|
|||
9
Task/Arrays/BASIC/arrays-9.basic
Normal file
9
Task/Arrays/BASIC/arrays-9.basic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
REDIM dynamicArray(10) AS INTEGER
|
||||
|
||||
dynamicArray(0) = -1
|
||||
PRINT dynamicArray(0)
|
||||
|
||||
REDIM dynamicArray(20)
|
||||
|
||||
dynamicArray(20) = 1
|
||||
PRINT dynamicArray(0), dynamicArray(20)
|
||||
18
Task/Arrays/Bc/arrays.bc
Normal file
18
Task/Arrays/Bc/arrays.bc
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
/* Put the value 42 into array g at index 3 */
|
||||
g[3] = 42
|
||||
/* Look at some other elements in g */
|
||||
g[2]
|
||||
0
|
||||
g[4342]
|
||||
0
|
||||
/* Look at the elements of another array */
|
||||
a[543]
|
||||
0
|
||||
/* Array names don't conflict with names of ordinary (scalar) identifiers */
|
||||
g
|
||||
0
|
||||
g = 123
|
||||
g
|
||||
123
|
||||
g[3]
|
||||
42
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
#include <array>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
std::array<std::string, 3> words = {"One", "Four", "Eight"};
|
||||
words[2] = "Three";
|
||||
words.at(1) = "Two";
|
||||
|
||||
std::reverse(words.begin(), words.end());
|
||||
|
||||
for(auto& word: words) std::cout << word << " ";
|
||||
std::cout << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
// Qt
|
||||
QVector<int> myArray4(10);
|
||||
myArray4.push_back(1);
|
||||
myArray4.push_back(2);
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
// MFC
|
||||
CArray<int,int> myArray5(10);
|
||||
myArray5.Add(1);
|
||||
myArray5.Add(2);
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
int myArray[2];
|
||||
|
||||
myArray[0] = 1;
|
||||
myArray[1] = 3;
|
||||
|
||||
cout << myArray[1] << endl;
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
int* myArray = new int[10];
|
||||
|
||||
myArray[0] = 1;
|
||||
myArray[1] = 3;
|
||||
|
||||
cout << myArray[1] << endl;
|
||||
delete [] myArray;
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
vector<int> myArray2;
|
||||
|
||||
myArray2.push_back(1);
|
||||
myArray2.push_back(3);
|
||||
|
||||
myArray2[0] = 2;
|
||||
|
||||
cout << myArray2[0] << endl;
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
#include <boost/Array.hpp>
|
||||
#include <algorithm>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::array<int, 3> A;
|
||||
A[0] = 5; // not bounds checked
|
||||
A[1] = 2;
|
||||
A.at(2) = 3; // this is bounds checked.
|
||||
|
||||
cout << A[0] << endl; // not bounds checked
|
||||
|
||||
for (int i =0; i < 3; ++i) {
|
||||
cout << A.at(i) << endl; // this is bounds checked
|
||||
}
|
||||
|
||||
// use it as you would any STL ordered container.
|
||||
std::reverse(A.begin(),A.end());
|
||||
BOOST_FOREACH(int i, A){cout << i << endl;}
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
array :: {Real}
|
||||
array = createArray 10 3.1415
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
array :: {Int}
|
||||
array = {x \\ x <- [1 .. 10]}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
array :: {!Int}
|
||||
array = {x \\ x <- [1 .. 10]}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
array :: {#Char}
|
||||
array = {x \\ x <- ['a' .. 'z']}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
array :: {String}
|
||||
array = {"Hello", "World"}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
array1 = []
|
||||
array1[0] = "Dillenidae"
|
||||
array1[1] = "animus"
|
||||
array1[2] = "Kona"
|
||||
alert "Elements of array1: " + array1 # Dillenidae,animus,Kona
|
||||
|
||||
array2 = ["Cepphus", "excreta", "Gansu"]
|
||||
alert "Value of array2[1]: " + array2[1] # excreta
|
||||
|
|
@ -1 +0,0 @@
|
|||
<cfset arr1 = ArrayNew(1)>
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
<cfscript>
|
||||
arr2 = ArrayNew(2);
|
||||
</cfscript>
|
||||
|
|
@ -1 +1 @@
|
|||
#var aStaticArray := (1, 2, 3).
|
||||
var aStaticArray := (1, 2, 3).
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#var anArray := system'Array new &length:3.
|
||||
anArray@0 := 1.
|
||||
anArray@1 := 2.
|
||||
anArray@2 := 3.
|
||||
var anArray := system'Array new:3.
|
||||
anArray[0] := 1.
|
||||
anArray[1] := 2.
|
||||
anArray[2] := 3.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
#var(int:3)aStackAllocatedArray.
|
||||
aStackAllocatedArray@0 := 1.
|
||||
aStackAllocatedArray@1 := 2.
|
||||
aStackAllocatedArray@2 := 3.
|
||||
int[] aStackAllocatedArray(3).
|
||||
aStackAllocatedArray[0] := 1.
|
||||
aStackAllocatedArray[1] := 2.
|
||||
aStackAllocatedArray[2] := 3.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#var aDynamicArray := ArrayList new.
|
||||
var aDynamicArray := ArrayList new.
|
||||
aDynamicArray += 1.
|
||||
aDynamicArray += 2.
|
||||
aDynamicArray += 4.
|
||||
|
||||
aDynamicArray@2 := 3.
|
||||
aDynamicArray[2] := 3.
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
system'console writeLine:(anArray@0).
|
||||
system'console writeLine:(aStackAllocatedArray@1).
|
||||
system'console writeLine:(aDynamicArray@2).
|
||||
system'console writeLine(anArray[0]).
|
||||
system'console writeLine(aStackAllocatedArray[1]).
|
||||
system'console writeLine(aDynamicArray[2]).
|
||||
|
|
|
|||
|
|
@ -1,41 +0,0 @@
|
|||
#APPTYPE CONSOLE
|
||||
|
||||
DIM v[-1 TO 1] ' static Variant
|
||||
v[-1] = -1
|
||||
v[0] = "zero"
|
||||
v[1] = !1.0
|
||||
FOREACH DIM e IN v
|
||||
PRINT e, " ";
|
||||
NEXT
|
||||
PRINT
|
||||
|
||||
DIM i[-1 TO 1] AS INTEGER ' static strong-type Integer/Single/Double/String
|
||||
i[-1] = -1
|
||||
i[0] = "zero"
|
||||
i[1] = !1
|
||||
FOREACH e IN i
|
||||
PRINT e, " ";
|
||||
NEXT
|
||||
PRINT
|
||||
|
||||
DIM d[] AS INTEGER ' dynamic strong-type Integer/Single/Double/String
|
||||
d[] = -1
|
||||
d[] = "zero"
|
||||
d[] = !1
|
||||
FOREACH e IN d
|
||||
PRINT e, " ";
|
||||
NEXT
|
||||
PRINT
|
||||
|
||||
DIM a[] = {-1, "zero", !1} ' dynamic Variant w/ anonymous array initialization
|
||||
FOREACH e IN a
|
||||
PRINT e, " ";
|
||||
NEXT
|
||||
PRINT
|
||||
|
||||
FOREACH e IN {-1, "zero", !1} ' anonymous Variant
|
||||
PRINT e, " ";
|
||||
NEXT
|
||||
PRINT
|
||||
|
||||
PAUSE
|
||||
19
Task/Arrays/Gambas/arrays-2.gambas
Normal file
19
Task/Arrays/Gambas/arrays-2.gambas
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
Public Sub Main()
|
||||
Dim sFixedArray As String[] = ["Rosetta", "code", "is", "a", "programming", "chrestomathy", "site"]
|
||||
Dim sFixedArray1 As New String[10]
|
||||
Dim iDynamicArray As New Integer[]
|
||||
Dim siCount As Short
|
||||
|
||||
For siCount = 1 To 10
|
||||
iDynamicArray.Add(siCount)
|
||||
Next
|
||||
|
||||
sFixedArray1[5] = "Hello"
|
||||
sFixedArray1[6] = " world!"
|
||||
|
||||
Print sFixedArray.Join(" ")
|
||||
Print iDynamicArray[5]
|
||||
|
||||
Print sFixedArray1[5] & sFixedArray1[6]
|
||||
|
||||
End
|
||||
9
Task/Arrays/Halon/arrays.halon
Normal file
9
Task/Arrays/Halon/arrays.halon
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
$array = [];
|
||||
|
||||
$array[] = 1;
|
||||
$array["key"] = 3;
|
||||
|
||||
$array[0] = 2;
|
||||
|
||||
echo $array[0];
|
||||
echo $array["key"];
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
REAL :: n = 3, Astat(n), Bdyn(1, 1)
|
||||
|
||||
Astat(2) = 2.22222222
|
||||
WRITE(Messagebox, Name) Astat(2)
|
||||
|
||||
ALLOCATE(Bdyn, 2*n, 3*n)
|
||||
Bdyn(n-1, n) = -123
|
||||
WRITE(Row=27) Bdyn(n-1, n)
|
||||
|
||||
ALIAS(Astat, n-1, last2ofAstat, 2)
|
||||
WRITE(ClipBoard) last2ofAstat ! 2.22222222 0
|
||||
|
|
@ -1,98 +0,0 @@
|
|||
record aThing(a, b, c) # arbitrary object (record or class) for illustration
|
||||
|
||||
procedure main()
|
||||
A0 := [] # empty list
|
||||
A0 := list() # empty list (default size 0)
|
||||
A0 := list(0) # empty list (literal size 0)
|
||||
|
||||
A1 := list(10) # 10 elements, default initializer &null
|
||||
A2 := list(10, 1) # 10 elements, initialized to 1
|
||||
|
||||
# literal array construction - arbitrary dynamically typed members
|
||||
A3 := [1, 2, 3, ["foo", "bar", "baz"], aThing(1, 2, 3), "the end"]
|
||||
|
||||
# left-end workers
|
||||
# NOTE: get() is a synonym for pop() which allows nicely-worded use of put() and get() to implement queues
|
||||
#
|
||||
Q := [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||
x := pop(A0) # x is 1
|
||||
x := get(A0) # x is 2
|
||||
push(Q,0)
|
||||
# Q is now [0,3, 4, 5, 6, 7, 8, 9, 10]
|
||||
|
||||
# right-end workers
|
||||
x := pull(Q) # x is 10
|
||||
put(Q, 100) # Q is now [0, 3, 4, 5, 6, 7, 8, 9, 100]
|
||||
|
||||
# push and put return the list they are building
|
||||
# they also can have multiple arguments which work like repeated calls
|
||||
|
||||
Q2 := put([],1,2,3) # Q2 is [1,2,3]
|
||||
Q3 := push([],1,2,3) # Q3 is [3,2,1]
|
||||
Q4 := push(put(Q2),4),0] # Q4 is [0,1,2,3,4] and so is Q2
|
||||
|
||||
# array access follows with A as the sample array
|
||||
A := [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
|
||||
|
||||
# get element indexed from left
|
||||
x := A[1] # x is 10
|
||||
x := A[2] # x is 20
|
||||
x := A[10] # x is 100
|
||||
|
||||
# get element indexed from right
|
||||
x := A[-1] # x is 100
|
||||
x := A[-2] # x is 90
|
||||
x := A[-10] # x is 10
|
||||
|
||||
# copy array to show assignment to elements
|
||||
B := copy(A)
|
||||
|
||||
# assign element indexed from left
|
||||
B[1] := 11
|
||||
B[2] := 21
|
||||
B[10] := 101
|
||||
# B is now [11, 21, 30, 50, 60, 60, 70, 80, 90, 101]
|
||||
|
||||
# assign element indexed from right - see below
|
||||
B[-1] := 102
|
||||
B[-2] := 92
|
||||
B[-10] := 12
|
||||
# B is now [12, 21, 30, 50, 60, 60, 70, 80, 92, 102]
|
||||
|
||||
# list slicing
|
||||
# the unusual nature of the slice - returning 1 less element than might be expected
|
||||
# in many languages - is best understood if you imagine indexes as pointing to BEFORE
|
||||
# the item of interest. When a slice is made, the elements between the two points are
|
||||
# collected. eg in the A[3 : 6] sample, it will get the elements between the [ ] marks
|
||||
#
|
||||
# sample list: 10 20 [30 40 50] 60 70 80 90 100
|
||||
# positive indexes: 1 2 3 4 5 6 7 8 9 10 11
|
||||
# non-positive indexes: -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
|
||||
#
|
||||
# I have deliberately drawn the indexes between the positions of the values.
|
||||
# The nature of this indexing brings simplicity to string operations
|
||||
#
|
||||
# list slicing can also use non-positive indexes to access values from the right.
|
||||
# The final index of 0 shown above shows how the end of the list can be nominated
|
||||
# without having to know it's length
|
||||
#
|
||||
# NOTE: list slices are distinct lists, so assigning to the slice
|
||||
# or a member of the slice does not change the values in A
|
||||
#
|
||||
# Another key fact to understand: once the non-positive indexes and length-offsets are
|
||||
# resolved to a simple positive index, the index pair (if two are given) are swapped
|
||||
# if necessary to yield the elements between the two.
|
||||
#
|
||||
S := A[3 : 6] # S is [30, 40, 50]
|
||||
S := A[6 : 3] # S is [30, 40, 50] not illegal or erroneous
|
||||
S := A[-5 : -8] # S is [30, 40, 50]
|
||||
S := A[-8 : -5] # S is [30, 40, 50] also legal and meaningful
|
||||
|
||||
# list slicing with length request
|
||||
S := A[3 +: 3] # S is [30, 40, 50]
|
||||
S := A[6 -: 3] # S is [30, 40, 50]
|
||||
S := A[-8 +: 3] # S is [30, 40, 50]
|
||||
S := A[-5 -: 3] # S is [30, 40, 50]
|
||||
S := A[-8 -: -3] # S is [30, 40, 50]
|
||||
S := A[-5 +: -3] # S is [30, 40, 50]
|
||||
end
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
# Unicon provides a number of extensions
|
||||
# insert and delete work on lists allowing changes in the middle
|
||||
# possibly others
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
ArrayList <Integer> list = new ArrayList <Integer>();//optionally add an initial size as an argument
|
||||
list.add(5);//appends to the end of the list
|
||||
list.add(1, 6);//assigns the element at index 1
|
||||
List<Integer> list = new ArrayList<Integer>(); // optionally add an initial size as an argument
|
||||
list.add(5); // appends to the end of the list
|
||||
list.add(1, 6); // inserts an element at index 1
|
||||
System.out.println(list.get(0));
|
||||
|
|
|
|||
5
Task/Arrays/Lang5/arrays.lang5
Normal file
5
Task/Arrays/Lang5/arrays.lang5
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
[]
|
||||
1 append
|
||||
['foo 'bar] append
|
||||
2 reshape
|
||||
0 remove 2 swap 2 compress collapse .
|
||||
6
Task/Arrays/OoRexx/arrays.rexx
Normal file
6
Task/Arrays/OoRexx/arrays.rexx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
a = .array~new -- create a zero element array
|
||||
b = .array~new(10) -- create an array with initial size of 10
|
||||
c = .array~of(1, 2, 3) -- creates a 3 element array holding objects 1, 2, and 3
|
||||
a[3] = "Fred" -- assign an item
|
||||
b[2] = a[3] -- retrieve an item from the array
|
||||
c~append(4) -- adds to end. c[4] == 4 now
|
||||
4
Task/Arrays/SPL/arrays.spl
Normal file
4
Task/Arrays/SPL/arrays.spl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
a[1] = 2.5
|
||||
a[2] = 3
|
||||
a[3] = "Result is "
|
||||
#.output(a[3],a[1]+a[2])
|
||||
35
Task/Arrays/Simula/arrays-1.simula
Normal file
35
Task/Arrays/Simula/arrays-1.simula
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
BEGIN
|
||||
|
||||
PROCEDURE STATIC;
|
||||
BEGIN
|
||||
INTEGER ARRAY X(0:4);
|
||||
|
||||
X(0) := 10;
|
||||
X(1) := 11;
|
||||
X(2) := 12;
|
||||
X(3) := 13;
|
||||
X(4) := X(0);
|
||||
|
||||
OUTTEXT("STATIC AT 4: ");
|
||||
OUTINT(X(4), 0);
|
||||
OUTIMAGE
|
||||
END STATIC;
|
||||
|
||||
PROCEDURE DYNAMIC(N); INTEGER N;
|
||||
BEGIN
|
||||
INTEGER ARRAY X(0:N-1);
|
||||
|
||||
X(0) := 10;
|
||||
X(1) := 11;
|
||||
X(2) := 12;
|
||||
X(3) := 13;
|
||||
X(4) := X(0);
|
||||
|
||||
OUTTEXT("DYNAMIC AT 4: ");
|
||||
OUTINT(X(4),0);
|
||||
OUTIMAGE
|
||||
END DYNAMIC;
|
||||
|
||||
STATIC;
|
||||
DYNAMIC(5)
|
||||
END ARRAYS.
|
||||
145
Task/Arrays/Simula/arrays-2.simula
Normal file
145
Task/Arrays/Simula/arrays-2.simula
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
BEGIN
|
||||
|
||||
CLASS ITEM;;
|
||||
|
||||
CLASS ITEMARRAY(N); INTEGER N;
|
||||
BEGIN
|
||||
REF(ITEM) ARRAY DATA(1:N);
|
||||
OUTTEXT("NEW ITEMARRAY WITH "); OUTINT(N, 0); OUTTEXT(" ELEMENTS");
|
||||
OUTIMAGE;
|
||||
END;
|
||||
|
||||
CLASS ARRAYLIST;
|
||||
BEGIN
|
||||
|
||||
PROCEDURE EXPAND(N); INTEGER N;
|
||||
BEGIN
|
||||
INTEGER I;
|
||||
REF(ITEMARRAY) TEMP;
|
||||
OUTTEXT("EXPAND TO CAPACITY "); OUTINT(N, 0); OUTIMAGE;
|
||||
TEMP :- NEW ITEMARRAY(N);
|
||||
FOR I := 1 STEP 1 UNTIL SIZE DO
|
||||
TEMP.DATA(I) :- ITEMS.DATA(I);
|
||||
ITEMS :- TEMP;
|
||||
END;
|
||||
|
||||
PROCEDURE ADD(T); REF(ITEM) T;
|
||||
BEGIN
|
||||
IF SIZE + 1 > CAPACITY THEN
|
||||
BEGIN
|
||||
CAPACITY := 2 * CAPACITY;
|
||||
EXPAND(CAPACITY);
|
||||
END;
|
||||
SIZE := SIZE + 1;
|
||||
ITEMS.DATA(SIZE) :- T;
|
||||
OUTTEXT("SIZE IS "); OUTINT(SIZE, 0); OUTIMAGE;
|
||||
END;
|
||||
|
||||
PROCEDURE REMOVE(I); INTEGER I;
|
||||
BEGIN
|
||||
INTEGER J;
|
||||
IF I < 1 OR I > SIZE THEN ERROR("REMOVE: INDEX OUT OF BOUNDS");
|
||||
FOR J := I STEP 1 UNTIL SIZE - 1 DO
|
||||
ITEMS.DATA(J) :- ITEMS.DATA(J + 1);
|
||||
ITEMS.DATA(SIZE) :- NONE;
|
||||
SIZE := SIZE - 1;
|
||||
END;
|
||||
|
||||
REF(ITEM) PROCEDURE GET(I); INTEGER I;
|
||||
BEGIN
|
||||
IF I < 1 OR I > SIZE THEN ERROR("GET: INDEX OUT OF BOUNDS");
|
||||
GET :- ITEMS.DATA(I);
|
||||
END;
|
||||
|
||||
INTEGER CAPACITY;
|
||||
INTEGER SIZE;
|
||||
REF(ITEMARRAY) ITEMS;
|
||||
|
||||
CAPACITY := 20;
|
||||
SIZE := 0;
|
||||
EXPAND(CAPACITY);
|
||||
|
||||
END;
|
||||
|
||||
|
||||
ITEM CLASS TEXTITEM(TXT); TEXT TXT;;
|
||||
|
||||
ARRAYLIST CLASS TEXTARRAYLIST;
|
||||
BEGIN
|
||||
PROCEDURE ADD(T); TEXT T;
|
||||
THIS TEXTARRAYLIST QUA ARRAYLIST.ADD(NEW TEXTITEM(T));
|
||||
TEXT PROCEDURE GET(I); INTEGER I;
|
||||
GET :- THIS TEXTARRAYLIST QUA ARRAYLIST.GET(I) QUA TEXTITEM.TXT;
|
||||
END;
|
||||
|
||||
|
||||
ITEM CLASS REALITEM(X); REAL X;;
|
||||
|
||||
ARRAYLIST CLASS REALARRAYLIST;
|
||||
BEGIN
|
||||
PROCEDURE ADD(X); REAL X;
|
||||
THIS REALARRAYLIST QUA ARRAYLIST.ADD(NEW REALITEM(X));
|
||||
REAL PROCEDURE GET(I); INTEGER I;
|
||||
GET := THIS REALARRAYLIST QUA ARRAYLIST.GET(I) QUA REALITEM.X;
|
||||
END;
|
||||
|
||||
|
||||
REF(TEXTARRAYLIST) LINES;
|
||||
REF(REALARRAYLIST) REALS;
|
||||
INTEGER I;
|
||||
|
||||
LINES :- NEW TEXTARRAYLIST;
|
||||
LINES.ADD("WE");
|
||||
LINES.ADD("HAVE");
|
||||
LINES.ADD("SEEN");
|
||||
LINES.ADD("THAT");
|
||||
LINES.ADD("ARRAYS");
|
||||
LINES.ADD("ARE");
|
||||
LINES.ADD("A");
|
||||
LINES.ADD("VERY");
|
||||
LINES.ADD("CONVENIENT");
|
||||
LINES.ADD("WAY");
|
||||
LINES.ADD("OF");
|
||||
LINES.ADD("STORING");
|
||||
LINES.ADD("SIMPLE");
|
||||
LINES.ADD("VALUES");
|
||||
LINES.ADD("AND");
|
||||
LINES.ADD("REFERENCES");
|
||||
LINES.ADD("TO");
|
||||
LINES.ADD("MORE");
|
||||
LINES.ADD("COMPLEX");
|
||||
LINES.ADD("CLASS");
|
||||
LINES.ADD("OBJECTS");
|
||||
LINES.ADD("IN");
|
||||
LINES.ADD("AN");
|
||||
LINES.ADD("ORDERED");
|
||||
LINES.ADD("LIST");
|
||||
LINES.ADD(".");
|
||||
|
||||
FOR I := 1 STEP 1 UNTIL LINES.SIZE DO
|
||||
BEGIN
|
||||
OUTINT(I, 0); OUTTEXT(": ");
|
||||
OUTTEXT(LINES.GET(I)); OUTIMAGE;
|
||||
END;
|
||||
|
||||
|
||||
REALS :- NEW REALARRAYLIST;
|
||||
FOR I := 1 STEP 1 UNTIL 10 DO
|
||||
REALS.ADD(I * I);
|
||||
|
||||
FOR I := 1 STEP 1 UNTIL REALS.SIZE DO
|
||||
BEGIN
|
||||
OUTINT(I, 4); OUTTEXT(": ");
|
||||
OUTFIX(REALS.GET(I),2,10); OUTIMAGE;
|
||||
END;
|
||||
|
||||
FOR I := REALS.SIZE STEP - 2 UNTIL 1 DO
|
||||
REALS.REMOVE(I);
|
||||
|
||||
FOR I := 1 STEP 1 UNTIL REALS.SIZE DO
|
||||
BEGIN
|
||||
OUTINT(I, 4); OUTTEXT(": ");
|
||||
OUTFIX(REALS.GET(I),2,10); OUTIMAGE;
|
||||
END;
|
||||
|
||||
END;
|
||||
8
Task/Arrays/Stata/arrays-1.stata
Normal file
8
Task/Arrays/Stata/arrays-1.stata
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
matrix a = 2,9,4\7,5,3\6,1,8
|
||||
display det(a)
|
||||
matrix svd u d v = a
|
||||
matrix b = u*diag(d)*v'
|
||||
matrix list b
|
||||
* store the u and v matrices in the current dataset
|
||||
svmat u
|
||||
svmat v
|
||||
7
Task/Arrays/Stata/arrays-2.stata
Normal file
7
Task/Arrays/Stata/arrays-2.stata
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mata
|
||||
a = 2,9,4\7,5,3\6,1,8
|
||||
det(a)
|
||||
svd(a, u=., s=., v=.)
|
||||
// Notice that to reconstruct the matrix, v is not transposed here,
|
||||
// while it is with -matrix svd- in Stata.
|
||||
u*diag(s)*v
|
||||
|
|
@ -3,4 +3,4 @@ var anyArray = [Any]()
|
|||
anyArray.append("foo") // Adding to an Array
|
||||
anyArray.append(1) // ["foo", 1]
|
||||
anyArray.removeAtIndex(1) // Remove object
|
||||
anyArray[0] = "bar" // ["bar"]]
|
||||
anyArray[0] = "bar" // ["bar"]
|
||||
|
|
|
|||
1
Task/Arrays/Unicon/arrays.unicon
Normal file
1
Task/Arrays/Unicon/arrays.unicon
Normal file
|
|
@ -0,0 +1 @@
|
|||
L := list(100); L[12] := 7; a := array(100, 0.0); a[3] +:= a[1]+a[2]
|
||||
5
Task/Arrays/Zkl/arrays.zkl
Normal file
5
Task/Arrays/Zkl/arrays.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
var array=List(); // array of size 0
|
||||
array=(0).pump(10,List().write,5).copy(); // [writable] array of size 10 filled with 5
|
||||
array[3]=4;
|
||||
array[3] //-->4
|
||||
array+9; //append a 9 to the end, same as array.append(9)
|
||||
Loading…
Add table
Add a link
Reference in a new issue