9 October 2013

String sorting program in c#.net



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter a string");
            StringBuilder s1 = new StringBuilder(Console.ReadLine());
            char a;
            int i, j;
            for (i = 0; i < s1.Length; i++)
            {
                for (j = i; j < s1.Length; j++)
                {
                    if (s1[i] > s1[j])
                    {
                        a = s1[i];
                        s1[i] = s1[j];
                        s1[j] = a;
                    }
                }
                Console.Write(s1[i]);
            }
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment