reorder a list from outside in

Given a list l1 -> l2 -> ... -> ln-1 -> ln, produce a list l1 -> ln -> l2 -> ln-1 ...

Easy if you break the solution into manageable steps.

1) Find the midpoint of the list
2) Break into 2 lists from that midpoint
3) Reverse the second half
4) Merge the result

From http://www.programcreek.com/2012/11/top-10-algorithms-for-coding-interview/ (this one).

My solution in C#:


	        

Leave a comment -

Elliot

https://www.emikek.com

I'm a .NET, PHP, Python, and Javascript developer. Also Project Manager, Scrum Master, and Juilliard trained violist. You cannot connect with me on Facebook, Twitter, or LinkedIn so don't ask.