Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region License
- // Copyright (c) 2017, Vira
- // All rights reserved.
- // Solution: OneLiner
- // Project: OneLiner
- // Filename: Program.cs
- // Date - created:2017.04.26
- // Date - current: 2017.04.26
- #endregion
- #region Usings
- using System;
- using System.Linq;
- #endregion
- namespace OneLiner
- {
- internal class Program
- {
- public static void Main(string[] args)
- {
- // Generate items (not sorted)
- var a = Gen(100);
- // Sorting the array using the "Selection-Sort"-algorithm
- Enumerable.Range(0, a.Length - 1)
- .ToList()
- .ForEach(i => Swap(ref a, i,
- a.ToList().FindIndex(i, a.Length - i, x => x.Equals(a.ToList().GetRange(i, a.Length - i).Min()))));
- // Printing the sorted array:
- a.ToList().ForEach(Console.WriteLine);
- }
- private static int[] Gen(int count, int min = 0, int max = 101)
- {
- var rand = new Random(DateTime.Now.Millisecond);
- return Enumerable
- .Repeat(0, count)
- .Select(i => rand.Next(min, max))
- .ToArray();
- }
- private static void Swap(ref int[] src, int i1, int i2)
- {
- // Does not work :(
- //src[i1] ^= src[i2] ^= src[i1] ^= src[i2];
- var temp = src[i1];
- src[i1] = src[i2];
- src[i2] = temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement