Skip to content

Instantly share code, notes, and snippets.

@ianpreston
Created May 22, 2013 17:48
Show Gist options
  • Save ianpreston/5629463 to your computer and use it in GitHub Desktop.
Save ianpreston/5629463 to your computer and use it in GitHub Desktop.
Pyramid Sort
using System.IO;
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] elements = { 1, 8, 9, 13, 2, 7 };
List<int> elems = elements.OrderBy(x => x).Reverse().ToList();
List<int> pyramid = new List<int>();
bool start = false;
foreach(int e in elems)
{
if (start)
pyramid.Add(e);
else
pyramid.Insert(0, e);
start = !start;
}
foreach(int p in pyramid)
{
Console.WriteLine(p);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment