-
-
Save unilecs/aada6fc4fd6a3cdcf92f85873b68d0b3 to your computer and use it in GitHub Desktop.
Задача: Double Reverse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
public class Program | |
{ | |
public static void DoubleReverse(ref int[] arr, int ind_1, int ind_2, int ind_3, int ind_4) | |
{ | |
while (ind_1 < ind_2) | |
{ | |
int temp = arr[ind_1]; | |
arr[ind_1] = arr[ind_2]; | |
arr[ind_2] = temp; | |
ind_1++; | |
ind_2--; | |
} | |
while (ind_3 < ind_4) | |
{ | |
int temp = arr[ind_3]; | |
arr[ind_3] = arr[ind_4]; | |
arr[ind_4] = temp; | |
ind_3++; | |
ind_4--; | |
} | |
} | |
public static void Main() | |
{ | |
Console.WriteLine("UniLecs"); | |
int n = 9; | |
int[] arr = Enumerable.Range(1, n).ToArray(); | |
DoubleReverse(ref arr, 1, 4, 5, 8); | |
Console.WriteLine(string.Format("Answer = {0}", string.Join(" ", arr))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment