you can use merge, insertion, bubble and quick sort algorithmsQuick link http://betterexplained.com/articles/sorting-algorithms/
Array can be sorted using static method Array.Sort() which internally uses Qucksort algorithm.// sort int array int[] intArray = new int[5] { 7, 9, 2, 5, 3 }; Array.Sort(intArray); // write array foreach (int i in intArray) Console.Write(i + " "); // output: 2 3 5 7 9
public static int[] SortArray(int[] array){Array.Sort(array);return array;}
public static int[] SortAnArray(int[] array){for (int i = 0; i < array.Length; i++){for (int j = 0; j < array.Length; j++){var v1 = array[i];var v2 = array[j];if (v2 > v1){array[i] = v2;array[j] = v1;}}}return array;}
You can use 2 iteration or loop to solve this problem. First iteration for items & second for comparison.
you can use Bubble, Merge , Insertion or quick sort method...........
http://www.csharp-examples.net/sort-array/
Guys its Without using Sort() method sorry for mistype
using System; using System.Collections;namespace GenericApp {public class TestClass{// here int[] is return type public int[] SortMyArray(int[] str1){int i = 0;int j = i + 1;for (; i < (str1.Length - 1); i++){for (int k = i + 1; k < (str1.Length - 1); k++){if (str1[i] < str1[k]){continue;}else{int a = str1[k];str1[k] = str1[i];str1[i] = a;}}}return str1;}public static void Main(string[] aa){TestClass obj = new TestClass();// Define a int type of array which is unsortedint[] mylist = { 22, 10, 1, 5, 3, 9, 2 };// Check the out put before sortingfor (int i = 0; i < mylist.Length - 1; i++){Console.WriteLine(mylist[i]);}// Check the out put after sorting Console.WriteLine("\n After sorting int type array \n");// Calling a method SortMyArray(mylist) which has return type as int array // sorted the int type of array in method and override the sorted array into existing mylist arraymylist= obj.SortMyArray(mylist);// display the sorted int array for (int i = 0; i < mylist.Length - 1; i++){Console.WriteLine(mylist[i]);}Console.ReadLine();}} }