9
Reply

Sort an int type of array with using Sort() method in C#

Ashvani chaudhary

Ashvani chaudhary

Jul 02, 2015
2k
0

    you can use merge, insertion, bubble and quick sort algorithmsQuick link http://betterexplained.com/articles/sorting-algorithms/

    Devendra Gohel
    December 19, 2015
    0

    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

    Rajesh Singh
    December 05, 2015
    0

    public static int[] SortArray(int[] array){Array.Sort(array);return array;}

    Pawan Chand
    September 17, 2015
    0

    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;}

    Manu Prasad
    September 16, 2015
    0

    You can use 2 iteration or loop to solve this problem. First iteration for items & second for comparison.

    Sujeet Suman
    September 02, 2015
    0

    you can use Bubble, Merge , Insertion or quick sort method...........

    Pankaj Kumar Choudhary
    August 29, 2015
    0

    http://www.csharp-examples.net/sort-array/

    Munesh Sharma
    August 05, 2015
    0

    Guys its Without using Sort() method sorry for mistype

    Ashvani chaudhary
    July 07, 2015
    0

    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();}} }

    Ashvani chaudhary
    July 02, 2015
    0