Code: Select all
Export Function Remove(tab, value, mode);
var i, j, tmp;
begin
i := 1;
while(i <= tab) do
begin
if not tab[i] then
break;
if value in tab then
begin
if not mode then
tab := tab diff value
else
for j = 1 to tab do
if tab[j] = value then
begin
tab := Delete(tab, j);
break;
end;
i := i - 1;
if mode then
break;
end
else
if tab[i] and value in tab[i] then
begin
if not mode then
tmp := tab[i] diff value
else
for j = 1 to tab[i] do
if value = tab[i][j] then
begin
tmp := Delete(tab[i], j);
break;
end;
if tmp = [] then
begin
tab := Delete(tab, i);
end
else
tab := Replace(tab, i, tmp);
i := i - 1;
if mode then
break;
end;
i := i + 1;
end;
result := tab;
End;
Przykład użycia:Remove(tab, value, mode);
- tab -> tablica z jakimiś wartościami
- value -> wartość
- mode -> tryb, jeżeli ustawimy na true wówczas zostanie usunięta tylko pierwszy znaleziony element w tablicy równy podanej wartości, jeśli false wówczas wszystkie elementy równe podanej wartości zostaną usunięte
Code: Select all
Every 1 do
var tab;
begin
tab := [[3, 4], [4, 5], [3, 3, 3]];
tab := Remove(tab, 3, false);
display_strings := tab;
End;
// Zwróci [4, [4,5]] ponieważ wszystkie trójki zostaną skasowane