update
This commit is contained in:
parent
1f1ad49427
commit
6f050a029e
2496 changed files with 37609 additions and 3031 deletions
1
Task/Arrays/Aime/arrays-1.aime
Normal file
1
Task/Arrays/Aime/arrays-1.aime
Normal file
|
|
@ -0,0 +1 @@
|
|||
list l;
|
||||
3
Task/Arrays/Aime/arrays-2.aime
Normal file
3
Task/Arrays/Aime/arrays-2.aime
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
l_append(l, 3);
|
||||
l_append(l, "arrays");
|
||||
l_append(l, pow);
|
||||
2
Task/Arrays/Aime/arrays-3.aime
Normal file
2
Task/Arrays/Aime/arrays-3.aime
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
l_push(l, 3, .5);
|
||||
l_push(l, 4, __type(l));
|
||||
2
Task/Arrays/Aime/arrays-4.aime
Normal file
2
Task/Arrays/Aime/arrays-4.aime
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
l_p_integer(l, 5, -1024);
|
||||
l_p_real(l, 6, 88);
|
||||
1
Task/Arrays/Aime/arrays-5.aime
Normal file
1
Task/Arrays/Aime/arrays-5.aime
Normal file
|
|
@ -0,0 +1 @@
|
|||
l_query(l, 5);
|
||||
2
Task/Arrays/Aime/arrays-6.aime
Normal file
2
Task/Arrays/Aime/arrays-6.aime
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
l_q_real(l, 6);
|
||||
l_q_text(l, 1);
|
||||
|
|
@ -1,4 +1,16 @@
|
|||
// Qt
|
||||
QVector<int> myArray4(10);
|
||||
myArray4.push_back(1);
|
||||
myArray4.push_back(2);
|
||||
#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 +1,4 @@
|
|||
// MFC
|
||||
CArray<int,int> myArray5(10);
|
||||
myArray5.Add(1);
|
||||
myArray5.Add(2);
|
||||
// Qt
|
||||
QVector<int> myArray4(10);
|
||||
myArray4.push_back(1);
|
||||
myArray4.push_back(2);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
int myArray[2];
|
||||
|
||||
myArray[0] = 1;
|
||||
myArray[1] = 3;
|
||||
|
||||
cout << myArray[1] << endl;
|
||||
// MFC
|
||||
CArray<int,int> myArray5(10);
|
||||
myArray5.Add(1);
|
||||
myArray5.Add(2);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
int* myArray = new int[10];
|
||||
int myArray[2];
|
||||
|
||||
myArray[0] = 1;
|
||||
myArray[1] = 3;
|
||||
|
||||
cout << myArray[1] << endl;
|
||||
delete [] myArray;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
vector<int> myArray2;
|
||||
int* myArray = new int[10];
|
||||
|
||||
myArray2.push_back(1);
|
||||
myArray2.push_back(3);
|
||||
myArray[0] = 1;
|
||||
myArray[1] = 3;
|
||||
|
||||
myArray2[0] = 2;
|
||||
|
||||
cout << myArray2[0] << endl;
|
||||
cout << myArray[1] << endl;
|
||||
delete [] myArray;
|
||||
|
|
|
|||
|
|
@ -1,25 +1,8 @@
|
|||
#include <iostream>
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
vector<int> myArray2;
|
||||
|
||||
#include <boost/Array.hpp>
|
||||
#include <algorithm>
|
||||
#include <boost/foreach.hpp>
|
||||
myArray2.push_back(1);
|
||||
myArray2.push_back(3);
|
||||
|
||||
int main()
|
||||
{
|
||||
boost::array<int, 3> A;
|
||||
A[0] = 5; // not bounds checked
|
||||
A[1] = 2;
|
||||
A.at(2) = 3; // this is bounds checked.
|
||||
myArray2[0] = 2;
|
||||
|
||||
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;}
|
||||
}
|
||||
cout << myArray2[0] << endl;
|
||||
|
|
|
|||
25
Task/Arrays/C++/arrays-7.cpp
Normal file
25
Task/Arrays/C++/arrays-7.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#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;}
|
||||
}
|
||||
41
Task/Arrays/FBSL/arrays.fbsl
Normal file
41
Task/Arrays/FBSL/arrays.fbsl
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#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
|
||||
35
Task/Arrays/Seed7/arrays.seed7
Normal file
35
Task/Arrays/Seed7/arrays.seed7
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
$ include "seed7_05.s7i";
|
||||
|
||||
const type: charArray is array [char] string; # Define an array type for arrays with char index.
|
||||
const type: twoDim is array array char; # Define an array type for a two dimensional array.
|
||||
|
||||
const proc: main is func
|
||||
local
|
||||
var array integer: array1 is 10 times 0; # Array with 10 elements of 0.
|
||||
var array boolean: array2 is [0 .. 4] times TRUE; # Array with 5 elements of TRUE.
|
||||
var array integer: array3 is [] (1, 2, 3, 4); # Array with the elements 1, 2, 3, 4.
|
||||
var array string: array4 is [] ("foo", "bar"); # Array with string elements.
|
||||
var array char: array5 is [0] ('a', 'b', 'c'); # Array with indices starting from 0.
|
||||
const array integer: array6 is [] (2, 3, 5, 7, 11); # Array constant.
|
||||
var charArray: array7 is ['1'] ("one", "two"); # Array with char index starting from '1'.
|
||||
var twoDim: array8 is [] ([] ('a', 'b'), # Define two dimensional array.
|
||||
[] ('A', 'B'));
|
||||
begin
|
||||
writeln(length(array1)); # Get array length (= number of array elements).
|
||||
writeln(length(array2)); # Writes 5, because array2 has 5 array elements.
|
||||
writeln(array4[2]); # Get array element ("bar"). By default array indices start from 1.
|
||||
writeln(array5[1]); # Writes b, because the indices of array5 start from 0.
|
||||
writeln(array7['2']); # Writes two, because the indices of array7 start from '1'.
|
||||
writeln(array8[2][2]); # Writes B, because both indices start from 1.
|
||||
writeln(minIdx(array7)); # Get minumum index of array ('1').
|
||||
array3[1] := 5; # Replace element. Now array3 has the elements 5, 2, 3, 4.
|
||||
writeln(remove(array3, 3)); # Remove 3rd element. Now array3 has the elements 5, 2, 4.
|
||||
array1 := array6; # Assign a whole array.
|
||||
array1 &:= [] (13, 17); # Append an array.
|
||||
array1 &:= 19; # Append an element.
|
||||
array1 := array3[2 ..]; # Assign a slice beginning with the second element.
|
||||
array1 := array3[.. 5]; # Assign a slice up to the fifth element.
|
||||
array1 := array3[3 .. 4]; # Assign a slice from the third to the fourth element.
|
||||
array1 := array3[2 len 4]; # Assign a slice of four elements beginning with the second element.
|
||||
array1 := array3 & array6; # Concatenate two arrays and assign the result to array1.
|
||||
end func;
|
||||
Loading…
Add table
Add a link
Reference in a new issue