static String[] process(String[] emails) { String[] result = new String[emails.Length]; var comparer = new DomainComparer(); Array.Sort(emails, comparer); for (int i = 0, j = emails.Length - 1, k = 0; i < j; i++, j--, k += 2) //may need to revise this for some corner cases { result[k] = emails[j]; result[k + 1] = emails[i]; } return(result); }
static String[] process(String[] emails) { String[] result = new String[emails.Length]; var comparer = new DomainComparer(); Array.Sort(emails, comparer); for (int i = 0, j = emails.Length - 1, k = 0; i < j; i++, j--, k += 2) { if (i == j) { result[k] = emails[i]; } else { result[k] = emails[i]; result[k + 1] = emails[j]; } } return(result); }