Periyasamy Vellingirisamy
Write a program for character sorting from string using c#

Program for sorting string characters without using build in functions.

By Periyasamy Vellingirisamy in C# on Jun 01 2020
  • Periyasamy Vellingirisamy
    Jul, 2020 3

    Hi
    Refer below one.

    1. string str;
    2. char[] arr1;
    3. char ch;
    4. int i, j, l;
    5. Console.Write("\n\nSort a string array in ascending order :\n");
    6. Console.Write("--------------------------------------------\n");
    7. Console.Write("Input the string : ");
    8. str = Console.ReadLine();
    9. l = str.Length;
    10. arr1 = str.ToCharArray(0, l);
    11. for (i = 1; i < l; i++)
    12. for (j = 0; j < l - i; j++)
    13. if (arr1[j] > arr1[j + 1])
    14. {
    15. ch = arr1[j];
    16. arr1[j] = arr1[j + 1];
    17. arr1[j + 1] = ch;
    18. }
    19. Console.Write("After sorting the string appears like : \n");
    20. foreach (char c in arr1)
    21. {
    22. ch = c;
    23. Console.Write("{0} ", ch);
    24. }
    25. Console.WriteLine("\n");

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS