Visa spoiler
static void sort(int[] data)
{
bool nsort = true;
for (int i = 0; i < data.Length - 1 && nsort; i++)
{
nsort = false;
for (int j = 0; j < data.Length; j++)
{
if (data[j]>data[j+1])
{
nsort = true;
int tmp = data[j + 1];
data[j + 1] = data[j];
data[j] = tmp;
}
}
}
}
static void Main(string[] args)
{
Console.Write("Mata mej med en talföljd ");
string mat = (Console.ReadLine());
int[] vector = new int[mat.Length];
for (int i = 0; i < vector.Length; i++)
{
vector[i] = mat[i] - 48;
}
sort(vector);
for (int j = 0; j < vector.Length; j++)
{
Console.Write(" " + vector[j] + " ");
}
}
{
bool nsort = true;
for (int i = 0; i < data.Length - 1 && nsort; i++)
{
nsort = false;
for (int j = 0; j < data.Length; j++)
{
if (data[j]>data[j+1])
{
nsort = true;
int tmp = data[j + 1];
data[j + 1] = data[j];
data[j] = tmp;
}
}
}
}
static void Main(string[] args)
{
Console.Write("Mata mej med en talföljd ");
string mat = (Console.ReadLine());
int[] vector = new int[mat.Length];
for (int i = 0; i < vector.Length; i++)
{
vector[i] = mat[i] - 48;
}
sort(vector);
for (int j = 0; j < vector.Length; j++)
{
Console.Write(" " + vector[j] + " ");
}
}
// Frustrerad Programmerare :/