Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp4
{
class Program
{
static void Main(string[] args)
{
int q = Convert.ToInt32(Console.ReadLine());
string arrays = Console.ReadLine();
string[] arraysint = new string[q];
arraysint = arrays.Split(' ');
int[] numbers = Array.ConvertAll(arraysint, int.Parse);
int i;
int save = 0;
int j;
int temp;
int current = q - 1;
int[] maior = new int[1];
//int[] numbers = new int[q];
for (j = 0; j < q; j++)
{
for (i = 0; i < current + 1; i++)
{
if (current == 1)
{
goto final;
}
if (i == current)
{
if (current == save)
{
current--;
}
if (current < q - 1)
{
if (maior[0] == numbers[current] && maior[0] != 0)
{
current--;
}
}
temp = numbers[current];
numbers[save] = temp;
numbers[current] = maior[0];
current--;
}
if (maior[0] < numbers[i])
{
save = i;
maior[0] = numbers[i];
}
}
maior[0] = 0;
}
final:
Console.Clear();
for (i = 0; i < q; i++)
{
Console.Write(numbers[i] + " ");
}
Console.ReadKey();
}
}
}
input:
5
5 4 3 2 1
Output:
1 3 2 4 5
I've done everything, but I can not solve it. Someone help me there?