Блок-схемы

Алгоритмы: от сортировки пузырьком до численных методов

Модераторы: C_O_D_E, DeeJayC

Ответить
Demento
Сообщения: 2
Зарегистрирован: 15 ноя 2016, 05:41

17 ноя 2016, 02:17

Не знаю алгоритмы, нужна блок-схема, помогите пожалуйста.

Вот код:


using System;

namespace Permutations
{
class Program
{
static bool GenNextPermutation(int[] permutation)
{
int last = permutation.Length - 1;
while (last > 0 && permutation[last] < permutation[last - 1])
--last;
if (last == 0)
return false;
int firstThatBigger = permutation.Length - 1;
while (permutation[firstThatBigger] < permutation[last-1])
{
--firstThatBigger;
}
Swap(ref permutation[last - 1], ref permutation[firstThatBigger]);
for (int k = 0; k < (permutation.Length - last) / 2; ++k)
Swap(ref permutation[last + k], ref permutation[permutation.Length - 1 - k]);
return true;
}

private static void Swap(ref int a, ref int b)
{
var t = a;
a = b;
b = t;
}

static int[] GetFirstPermutation(int n)
{
var res = new int[n];
for (int i = 0; i < n; ++i)
res = i + 1;
return res;
}

static void Print(int[] permutation)
{
Console.WriteLine(string.Join(" ", permutation));
}

static void Main(string[] args)
{
int n = int.Parse(Console.ReadLine());
var permutation = GetFirstPermutation(n);
Print(permutation);
while (GenNextPermutation(permutation))
{
Print(permutation);
}
Console.WriteLine();
}
}
}
Ответить