Aborigenius

ReverseArray

Jul 1st, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ReverseArrayInPlace
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             ReverseArray(array);
  15.  
  16.             Console.WriteLine(string.Join(" ", array));
  17.         }
  18.         static void ReverseArray(int[] array)
  19.         {
  20.             int left = 0;
  21.             int right = array.Length - 1;
  22.             while (left < right)
  23.             {
  24.                 int temp = array[left];
  25.                 array[left] = array[right];
  26.                 array[right] = temp;
  27.                 left++;
  28.                 right--;
  29.             }
  30.             return;
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment