1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
| // Defining
int nums[] = { 0, 1, 2, 3, 4, 5 };
i[]@nums = { 0, 1, 2, 3, 4, 5 };
int a = 5;
i[]@nums = array(0, 1, 2, 3, 4, a); // just like set() for vectors
// Retrieving
int num = nums[3] // 2
i@num = i[]@nums[3] // 2
// Accessing, Slicing (VEX uses Python style slicing notation)
int start[] = nums[0:2]; // { 0, 1 }
int end[] = nums[-2:]; // { 4, 5 }
int rev[] = nums[::-1]; // { 5, 4, 3, 2, 1, 0 }
int odd[] = nums[1::2]; // { 1, 3, 5 }
// Sorting, Reversing
int nums[] = {5, 1, 4, 3, 8};
int sorted[] = sort(nums)); // {1, 4, 4, 5, 8}
int reversed[] = reverse(sort(nums))); // {8, 3, 4, 1, 5}
// Adding Elements
int numbers[] = {1, 2, 3, 4, 5, 6};
numbers[1] = 7; // {1, 7, 3, 4, 5, 6}
numbers[6] = 7; // {1, 2, 3, 4, 5, 6, 7}
append(numbers, 7); // {1, 2, 3, 4, 5, 6, 7}
// Finding Index of Value
int numbers[] = {5, 4, 3, 2, 1};
int index_of_4 = find(numbers, 4);
printf('%d', index_of_4 ); // 1
// Split string with a space to array of strings
string numbres = '1 2 3 4 5 6';
string array[] = split(numbres, ' ');
printf('%s', array); // {1, 2, 3, 4, 5, 6}
// Split integer into array of integers via strings
int int_number = 312654;
string string_number = itoa(int_number);
int int_numbers[];
for(int n=0; n<len(string_number); n++){
int_numbers[n] = atoi(string_number[n]);
}
int nums[] = int_numbers; // {3, 1, 2, 6, 5, 4}
int sorted[] = sort(int_numbers); // {1, 2, 3, 4, 5, 6}
int reversesorted[] = reverse(sort(int_numbers))); // {6, 5, 4, 3, 2, 1}
// Copying between arrays and vectors/matrices
float x[];
// Cf and P are vectors
x = set(P); // Assigns the components of P to the corresponding members of the array x
Cf = set(x); // Assigns the first 3 members of x as the components of the vector Cf
float x[] = {1, 2} // Not long enough to fill a vector
Cf = set(x); // Cf == {1, 2, 2}
|