07.01.2015, 16:16
Some more:
array_shift(array[], value, size = sizeof array)
Appends value to the end of array. Pushes the first value off and returns it, moves everything down.
array_unshift(array[], value, size = sizeof array)
Prepends value to the start of array. Pushes the last value off and returns it. Moves everything up.
array_shift(array[], value, size = sizeof array)
Appends value to the end of array. Pushes the first value off and returns it, moves everything down.
pawn Код:
array_shift(array[], value, size = sizeof array)
{
new returnval = array[0];
for(new i; i < size - 1; i++)
{
array[i] = array[i + 1];
}
array[size - 1] = value;
return returnval;
}
Код:
[0] = 1 [1] = 3 [2] = 5 [3] = 7 [4] = 13 [0] = 3 [1] = 5 [2] = 7 [3] = 13 [4] = 15
Prepends value to the start of array. Pushes the last value off and returns it. Moves everything up.
pawn Код:
array_unshift(array[], value, size = sizeof array)
{
new returnval = array[size - 1];
for(new i = size - 1; i > 0; i--)
{
array[i] = array[i - 1];
}
array[0] = value;
return returnval;
}
Код:
array[0] = 1 array[1] = 3 array[2] = 5 array[3] = 7 array[4] = 13 array[0] = 15 array[1] = 1 array[2] = 3 array[3] = 5 array[4] = 7