Inversão de um trecho do array
Escreva uma função que inverta o trecho do array entre os índices inicial e final (ambos incluídos). O restante do array deve permanecer igual.
Exemplos
Program.RangedReversal(new[] { 1, 2, 3, 4, 5, 6 }, 1, 3); // new[] { 1, 4, 3, 2, 5, 6 }
Program.RangedReversal(new[] { 1, 2, 3, 4, 5, 6 }, 0, 4); // new[] { 5, 4, 3, 2, 1, 6 }
Program.RangedReversal(new[] { 9, 8, 7, 4 }, 0, 0); // new[] { 9, 8, 7, 4 }Notas
- Os arrays são indexados a partir de zero.
- Os índices inicial e final sempre serão válidos para o array.
- O índice final sempre será maior ou igual ao inicial.
- Se os índices inicial e final forem iguais, retorne o array sem alterações.