Advertisement
skipter

List - Flip List Sides/ with/out last first and last index

Jul 11th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace _4.Flip_List_Sides
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<int> list = Console.ReadLine()
  11.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToList();
  14.  
  15.             ReverseList(list);
  16.  
  17.         }
  18.         private static void ReverseList(List<int> list)
  19.         {
  20.             var newList = new List<int>();
  21.             var lastNum = list.Count - 1;
  22.  
  23.             newList.Add(list[0]);
  24.  
  25.             for (int i = list.Count - 2; i >= 1; i--)
  26.             {
  27.                 newList.Add(list[i]);
  28.             }
  29.             newList.Add(list[lastNum]);
  30.             Console.WriteLine(string.Join(" ", newList));
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement