Összegzés
static int Szum(int n, int[] tomb)
{
if (n == -1) return 0;
else if (/*feltétel*/) return Szum(n-1, tomb) + tomb[n];
else return Szum(n-1, tomb);
}
Megszámolás
static int Darab(int n, int[] tomb)
{
if(n == -1) return 0;
else if (/*feltétel*/) return Darab(n-1, tomb) + 1;
else return Darab(n-1, tomb);
}
Maximum- és minimumkiválasztás
static (int,int) Max(int n, int[] tomb)
{
if(n == 0) return (0, tomb[0]);
else if (tomb[n] > Max(n-1, tomb).Item2) return (n, tomb[n]);
else return Max(n-1, tomb);
}
Eldöntés
static bool Eldont(int n, int[] tomb)
{
if(n == -1) return false;
else if (/*nem feltétel*/) return Eldont(n-1, tomb);
else return true;
}
Mind eldöntés / optimista eldöntés
static bool Mind(int n, int[] tomb)
{
if(n == -1) return true;
else if (/*feltétel*/) return Mind(n-1, tomb);
else return false;
}
Kiválasztás
static int Kivalaszt(int n, int[] tomb)
{
if(/*nem feltétel*/) return Kivalaszt(n-1, tomb);
else return n;
}
Keresés
static (bool, int) Keres(int n, int[] tomb)
{
if(n == -1) return (false, -1);
else if(/*nem feltétel*/) return Keres(n-1, tomb);
else return (true, n);
}
Másolás
static void Masol(int n, int[] tomb, int[] kimenet)
{
if(n == -1) return;
else
{
kimenet[n] = /*módosított tomb[n]*/;
Masol(n-1, tomb, kimenet);
}
}
// eeh, nem ideális megoldás (szerintem)
Kiválogatás (indexekre)
static void Kivalogat(int n, int[] tomb, List<int> kimenet)
{
if(n == -1) return;
else if(/*feltétel*/) kimenet.Add(n);
Kivalogat(n-1, tomb, kimenet);
}
További linkek
Programozási tételek (Programozási alapismeretek)
Programozási tételek 0-tól indexelve