Bubble Sort string array - CSharp System

CSharp examples for System:Array Sort

Description

Bubble Sort string array

Demo Code


using System.Text;
using System.Security.Cryptography;
using System.IO;/*from www.  ja  v a2s. com*/
using System;

public class Main{
        public static string[] BubbleSort(string[] r)
        {
            for (int i = 0; i < r.Length; i++)
            {
                bool flag = false;
                for (int j = r.Length - 2; j >= i; j--)
                {
                    if (string.CompareOrdinal(r[j + 1], r[j]) < 0)
                    {
                        string str = r[j + 1];
                        r[j + 1] = r[j];
                        r[j] = str;
                        flag = true;
                    }
                }
                if (!flag)
                {
                    return r;
                }
            }
            return r;
        }
}

Related Tutorials