Új hozzászólás Aktív témák
-
pmonitor
aktív tag
válasz
joysefke
#9468
üzenetére
Én így fordítottam át:
using System;
namespace IsmPerm
{
class Program
{
static int findCeilInt(int[] str, int first, int l, int h)
{
int ceilIndex = l;
for (int i = l + 1; i <= h; i++)
if (str[i] > first && str[i] < str[ceilIndex])
ceilIndex = i;
return ceilIndex;
}
static void Teszt_1(int[] tomb)
{ //https://www.geeksforgeeks.org/print-all-permutations-of-a-string-with-duplicates-allowed-in-input-string/
int size = tomb.Length;
Array.Sort(tomb);
bool isFinished = false;
while (!isFinished)
{
int x = 1, i;
for (int k = 0; k < size; ++k) Console.Write("{0} ", tomb[k]);
Console.WriteLine("");
for (i = size - 2; i >= 0; --i) if (tomb[i] < tomb[i + 1]) break;
if (i == -1) isFinished = true;
else
{
int ceilIndex = findCeilInt(tomb, tomb[i], i + 1, size - 1);
int temp = tomb[i];
tomb[i] = tomb[ceilIndex];
tomb[ceilIndex] = temp;
Array.Sort(tomb, i + 1, size - i - 1);
}
}
}
static void Main(string[] args)
{
int[] tomb = new int[] { 500, 500, 600, 600, 700};
Teszt_1(tomb);
Console.ReadKey();
}
}
}
Új hozzászólás Aktív témák
● ha kódot szúrsz be, használd a PROGRAMKÓD formázási funkciót!
- GYÖNYÖRŰ iPhone 13 mini 128GB Pink -1 ÉV GARANCIA - Kártyafüggetlen, MS4060, 100% Akkumulátor
- BESZÁMÍTÁS! GIGABYTE X570 AORUS ELITE X570 alaplap garanciával hibátlan működéssel
- Honor X6a 128GB, Kártyafüggetlen, 1 Év Garanciával
- GYÖNYÖRŰ iPhone SE 2020 256GB Black-1 ÉV GARANCIA - Kártyafüggetlen, MS4003, 100% Akkumulátor
- GYÖNYÖRŰ iPhone 13 Pro 256GB Sierra Blue -1 ÉV GARANCIA - Kártyafüggetlen, MS3358, 100% Akkumulátor
Állásajánlatok
Cég: BroadBit Hungary Kft.
Város: Budakeszi
Cég: PCMENTOR SZERVIZ KFT.
Város: Budapest

