I need to sort it with bubble sort from text file!
I made with sorting letters in words but don't know how to sort strings in alphabetical order, like that:
post
new
thread
=
new
post
thread
mine code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
string path = @"C:\test.txt";
FileStream fs = new FileStream(path, FileMode.Open);
StreamReader sr = new StreamReader(fs, Encoding.Default);
string text = sr.ReadToEnd();
string[] Text = text.Split(' ', '\n');
string[] outText = new string[Text.Length];
for (int i = 1; i < Text.Length-1 ; ++i)
{
char[] ch = Text[i].ToCharArray();
char[] cht = Text[i+1].ToCharArray();
bool bol = true;
while (bol)
{
bol = false;
for (int j = 0; j < Math.Min(Text[i].Length, Text[i + 1].Length); ++j)
{
if (ch[j] > cht[j])
{
string tmp = Text[i];
Text[i] = Text[i + 1];
Text[i + 1] = tmp;
bol = true;
}
}
}
Console.WriteLine(Text[i]);
//sorting letters
/*while (bol)
{
bol = false;
for (int j = 0; j < ch.Length - 1; j++)
{
if (ch[j] > ch[j + 1])
{
char tmp = ch[j];
ch[j] = ch[j + 1];
ch[j + 1] = tmp;
bol = true;
}
}
}
outText[i] = new string(ch);
Console.WriteLine(outText[i]);*/
}
Console.Write("\nPress any key to continue . . . ");
Console.ReadKey(true);
}
}
}