using System; class SortStringByLength { static int[,] Sort (int[,] array, int left, int right) { int i = left, j = right; int pivot = array [1,(left + right) / 2]; int temp = 0; while (i <= j) { while (array[1,i] < pivot) { i++; } while (pivot < array[1, j]) { j--; } if (i <= j) { // Swap the length and index of the string temp = array[1,i]; array[1,i] = array[1,j]; array[1,j]= temp; temp = array[0,i]; array[0,i] = array[0,j]; array[0,j]= temp; i++; j--; } } // Recursive calls if (left < j) { Sort(array, left, j); } if (i < right) { Sort(array, i, right); } return array; } static void Main() { //Define string array string[] stringArray={"abc", "a", "bcde", "abcde", "ab"}; //Define 2 dimentional array - 1st row index of strings in the array, 2nd row - length of the string in array int [,] stringArrayLenght=new int[2,stringArray.Length]; for (int i = 0; i < stringArray.Length; i++) { stringArrayLenght[0, i] = i; } for (int i = 0; i < stringArray.Length; i++) { stringArrayLenght[1,i] = stringArray[i].Length; Console.Write(stringArray[i] + " "); } Console.WriteLine(); Sort(stringArrayLenght, 0, stringArray.Length-1); //Print string in Console.WriteLine("Sorted: "); for (int i = 0; i < stringArray.Length; i++) { Console.Write(stringArray[stringArrayLenght[0, i]] + " "); } } }