Skip to content

Instantly share code, notes, and snippets.

@ip75
Created April 16, 2019 13:50
Show Gist options
  • Save ip75/216f91503d996352e9a66331e8cc9ec9 to your computer and use it in GitHub Desktop.
Save ip75/216f91503d996352e9a66331e8cc9ec9 to your computer and use it in GitHub Desktop.
public class Program
{
static private Queue<long> lifo = new Queue<long>();
static void walk(object[] root)
{
if (root == null) throw new ArgumentNullException(nameof(root));
foreach (var o in root)
{
if (o is long i)
{
lifo.Enqueue(i);
}
else
{
walk((object[]) o);
}
}
}
static void Main(string[] args)
{
object[] srcData = {new object[] {1L, 2L, new object[] {3L}}, 4L};
walk(srcData);
var array = lifo.ToArray();
foreach (var digit in array)
{
Console.WriteLine(digit);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment