M
M
MaximClown2021-03-20 22:26:18
Visual Basic
MaximClown, 2021-03-20 22:26:18

How to swap adjacent elements of a one-dimensional array?

There is a procedure that swaps the values ​​of variables: 60564c08c4534686946221.pngHow can I use it to swap adjacent elements of a one-dimensional array filled with ten random two-digit numbers?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BasiC2k, 2021-03-21
@BasiC2k

You iterate over the elements of the array through a loop with a step:
For i = 0 to Ubound(array) Step 2
That is, in pairs. And in the loop you change the values ​​of the elements:
array(i)
array(i+1)
using a temporary variable, as in your example.
It is advisable to check before that that the array has an even number of elements.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question