skipter icon

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

skipter | PRO | 07/11/17 06:55:32 PM UTC | 0 ⭐ | 320 👁️ | Never ⏰ | []
C# |

840 B

|

None

|

0 👍

/

0 👎

using System;
using System.Collections.Generic;
using System.Linq;
namespace _4.Flip_List_Sides
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> list = Console.ReadLine()
                .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                .Select(int.Parse)
                .ToList();
 
            ReverseList(list);
 
        }
        private static void ReverseList(List<int> list)
        {
            var newList = new List<int>();
            var lastNum = list.Count - 1;
 
            newList.Add(list[0]);
 
            for (int i = list.Count - 2; i >= 1; i--)
            {
                newList.Add(list[i]);
            }
            newList.Add(list[lastNum]);
            Console.WriteLine(string.Join(" ", newList));
        }
    }
}

Comments