其实跟数组的冒泡排序是一样的。。不过要先把字符串转尺闷为字符数组。告冲然后对字符数组进行操作,最后在把排好序的字符数组转为字符串
具体代码别人都写了我袜困歼就不写了
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Console
{
class Program
{
static void Main(string[] args)
{
string s = "hgdfjhjadefghijklmen";
char[] c = s.ToCharArray();
for (int i = 0; i < c.Length - 1; i++)
{
for (int j = i; j < c.Length - 1; j++)
{
if (c[i] > c[j])
{
char t = c[i];
c[i] = c[j];
c[j] = t;
}
}
}
System.Console.WriteLine(c);
}
}
}
不知道LZ说的是不是这个意思
private void TT()
{
string s = "纤胡乱升pkqabczdefy"毁陪拦;
char[] cs = s.ToCharArray();
Array.Sort(cs);
string news = null;
foreach (char c in cs)
{
news = string.Concat(news, c);
}
}