A
A
Alexey Anisimov2019-08-02 08:19:45
Java
Alexey Anisimov, 2019-08-02 08:19:45

Why is the body of the loop being lit?

static void insert(int[] array, int pos, int index) {
    int num = array[index];

    for (int i = pos + 1; i < index; i++) {
      int a = array[i];
      array[i] = array[i - 1];
      array[i] = a;
    }
    array[pos] = num;
  }

Run it in your debugger and take a look. With each new cycle, the results of the previous cycle are reset.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Griboks, 2019-08-02
@Griboks

int a = array[i];
array[i] = a;

Does this code bother you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question