Liste des Groupes | Revenir à cl c |
Some homies they be sayin’ recursion is Teh Evulz. Well, check thisokay, there are some class of things that suit good for recursion - and its probably good to spot whose they are
out. This program be recursing to the max, yo.
>
Peace.
>
----
/*
Generate permutations of a list of items.
Pass a list of arbitary words as command arguments, and this
program will print out all possible orderings of them.
*/
>
#include <iso646.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
>
typedef void (*permute_action)
(
const char * const * words
);
>
void permute
(
unsigned int nrwords,
const char * const * words,
permute_action action
)
{
if (nrwords > 0)
{
const char ** const permbuf = (const char **)malloc(nrwords * sizeof(char *));
bool * const used = (bool *)malloc(nrwords);
for (unsigned int i = 0; i < nrwords; ++i)
{
used[i] = false;
} /*for*/
>
void permute1
(
unsigned int depth
)
{
if (depth < nrwords)
{
for (unsigned int i = 0; i < nrwords; ++i)
{
if (not used[i])
{
permbuf[depth] = words[i];
used[i] = true;
permute1(depth + 1);
used[i] = false;
} /*if*/
} /*for*/
}
else
{
action(permbuf);
} /*if*/
} /*permute1*/
>
permute1(0);
>
free(permbuf);
free(used);
} /*if*/
} /*permute*/
>
int main
(
int argc,
char ** argv
)
{
const unsigned int nrwords = argc - 1;
unsigned int count = 0;
>
void collect
(
const char * const * words
)
{
count += 1;
fprintf(stdout, "[%d](", count);
for (unsigned int i = 0; i < nrwords; ++i)
{
if (i != 0)
{
fputs(", ", stdout);
} /*if*/
fputs(words[i], stdout);
} /*for*/
fputs(")\n", stdout);
} /*collect*/
>
permute
(
/*nrwords =*/ nrwords,
/*words =*/ (const char * const * )(argv + 1),
/*permute_action =*/ (permute_action)collect
);
>
fprintf(stdout, "Nr found: %d\n", count);
} /*main*/
>
Date | Sujet | # | Auteur | |
7 Apr 24 | Recursion, Yo | 102 | Lawrence D'Oliveiro | |
7 Apr 24 | Re: Recursion, Yo | 100 | fir | |
9 Apr 24 | Re: Recursion, Yo | 99 | Janis Papanagnou | |
9 Apr 24 | Re: Recursion, Yo | 7 | Lawrence D'Oliveiro | |
9 Apr 24 | Re: Recursion, Yo | 5 | Janis Papanagnou | |
9 Apr 24 | Re: Recursion, Yo | 4 | Ben Bacarisse | |
9 Apr 24 | Re: Recursion, Yo | 3 | Janis Papanagnou | |
9 Apr 24 | Re: Recursion, Yo | 2 | Keith Thompson | |
10 Apr 24 | Re: Recursion, Yo | 1 | Janis Papanagnou | |
9 Apr 24 | Re: Recursion, Yo | 1 | bart | |
9 Apr 24 | Re: Recursion, Yo | 91 | Ben Bacarisse | |
9 Apr 24 | Re: Recursion, Yo | 1 | Ben Bacarisse | |
10 Apr 24 | Re: Recursion, Yo | 89 | Lawrence D'Oliveiro | |
10 Apr 24 | Re: Recursion, Yo | 1 | Chris M. Thomasson | |
10 Apr 24 | Re: Recursion, Yo | 86 | David Brown | |
10 Apr 24 | Re: Recursion, Yo | 84 | Lawrence D'Oliveiro | |
10 Apr 24 | Re: Recursion, Yo | 83 | David Brown | |
10 Apr 24 | Re: Recursion, Yo | 73 | bart | |
10 Apr 24 | Re: Recursion, Yo | 71 | David Brown | |
11 Apr 24 | Re: Recursion, Yo | 70 | Lawrence D'Oliveiro | |
11 Apr 24 | Re: Recursion, Yo | 4 | Kaz Kylheku | |
11 Apr 24 | Heh heh... (Was: Recursion, Yo) | 3 | Kenny McCormack | |
11 Apr 24 | Re: Heh heh... (Was: Recursion, Yo) | 2 | Kaz Kylheku | |
11 Apr 24 | Re: Heh heh... (Was: Recursion, Yo) | 1 | Kenny McCormack | |
11 Apr 24 | Re: Recursion, Yo | 65 | David Brown | |
11 Apr 24 | Re: Recursion, Yo | 62 | Kaz Kylheku | |
11 Apr 24 | Re: Recursion, Yo | 1 | David Brown | |
12 Apr 24 | Re: Recursion, Yo | 60 | Lawrence D'Oliveiro | |
12 Apr 24 | Re: Recursion, Yo | 2 | Kaz Kylheku | |
12 Apr 24 | Re: Recursion, Yo | 1 | Dan Cross | |
12 Apr 24 | Re: Recursion, Yo | 57 | Janis Papanagnou | |
12 Apr 24 | Re: Recursion, Yo | 6 | David Brown | |
12 Apr 24 | Re: Recursion, Yo | 5 | Janis Papanagnou | |
12 Apr 24 | Re: Recursion, Yo | 3 | David Brown | |
13 Apr 24 | Re: Recursion, Yo | 2 | Janis Papanagnou | |
13 Apr 24 | Re: Recursion, Yo | 1 | David Brown | |
13 Apr 24 | Re: Recursion, Yo | 1 | Lawrence D'Oliveiro | |
12 Apr 24 | Re: Recursion, Yo | 45 | Lawrence D'Oliveiro | |
12 Apr 24 | Re: Recursion, Yo | 44 | Janis Papanagnou | |
12 Apr 24 | Re: Recursion, Yo | 1 | bart | |
13 Apr 24 | Re: Recursion, Yo | 42 | Lawrence D'Oliveiro | |
13 Apr 24 | Re: Recursion, Yo | 14 | Michael S | |
14 Apr 24 | Re: Recursion, Yo | 11 | Ben Bacarisse | |
14 Apr 24 | Re: Recursion, Yo | 10 | Michael S | |
15 Apr 24 | Re: Recursion, Yo | 9 | Janis Papanagnou | |
15 Apr 24 | Re: Recursion, Yo | 8 | Keith Thompson | |
15 Apr 24 | Re: Recursion, Yo | 7 | Ben Bacarisse | |
15 Apr 24 | Re: Recursion, Yo | 6 | Keith Thompson | |
15 Apr 24 | Re: Recursion, Yo | 2 | bart | |
15 Apr 24 | Re: Recursion, Yo | 1 | Ben Bacarisse | |
15 Apr 24 | Re: Recursion, Yo | 3 | Janis Papanagnou | |
15 Apr 24 | Re: Recursion, Yo | 1 | Janis Papanagnou | |
15 Apr 24 | Re: Recursion, Yo | 1 | Keith Thompson | |
14 Apr 24 | Re: Recursion, Yo | 2 | Lawrence D'Oliveiro | |
14 Apr 24 | Re: Recursion, Yo | 1 | Keith Thompson | |
13 Apr 24 | Re: Recursion, Yo | 27 | Janis Papanagnou | |
14 Apr 24 | Re: Recursion, Yo | 26 | Lawrence D'Oliveiro | |
14 Apr 24 | Re: Recursion, Yo | 25 | Ben Bacarisse | |
14 Apr 24 | Re: Recursion, Yo | 2 | bart | |
14 Apr 24 | Re: Recursion, Yo | 1 | Ben Bacarisse | |
15 Apr 24 | Re: Recursion, Yo | 22 | Lawrence D'Oliveiro | |
15 Apr 24 | Re: Recursion, Yo | 20 | Chris M. Thomasson | |
15 Apr 24 | Re: Recursion, Yo | 5 | Ben Bacarisse | |
16 Apr 24 | Re: Recursion, Yo | 4 | Lawrence D'Oliveiro | |
17 Apr 24 | Re: Recursion, Yo | 3 | Ben Bacarisse | |
18 Apr 24 | Re: Recursion, Yo | 2 | Lawrence D'Oliveiro | |
22 Apr 24 | Re: Recursion, Yo | 1 | Janis Papanagnou | |
15 Apr 24 | Re: Recursion, Yo | 14 | Janis Papanagnou | |
16 Apr 24 | Re: Recursion, Yo | 2 | Lawrence D'Oliveiro | |
22 Apr 24 | Re: Recursion, Yo | 1 | Janis Papanagnou | |
16 Apr 24 | Re: Recursion, Yo | 11 | Michael S | |
19 Apr 24 | Re: Recursion, Yo | 9 | Tim Rentsch | |
19 Apr 24 | Re: Recursion, Yo | 4 | bart | |
20 Apr 24 | Re: Recursion, Yo | 3 | Ben Bacarisse | |
20 Apr 24 | Re: Recursion, Yo | 1 | Keith Thompson | |
20 Apr 24 | Re: Recursion, Yo | 1 | Kaz Kylheku | |
19 Apr 24 | Re: Recursion, Yo | 1 | Keith Thompson | |
19 Apr 24 | Re: Recursion, Yo | 2 | Keith Thompson | |
20 Apr 24 | Re: Recursion, Yo | 1 | Tim Rentsch | |
20 Apr 24 | Re: Recursion, Yo | 1 | Tim Rentsch | |
22 Apr 24 | Re: Recursion, Yo | 1 | Janis Papanagnou | |
15 Apr 24 | Re: Recursion, Yo | 1 | Ben Bacarisse | |
12 Apr 24 | Re: Recursion, Yo | 4 | bart | |
12 Apr 24 | Re: Recursion, Yo | 2 | Janis Papanagnou | |
12 Apr 24 | Re: Recursion, Yo | 1 | bart | |
13 Apr 24 | Re: Recursion, Yo | 1 | Keith Thompson | |
13 Apr 24 | Re: Recursion, Yo | 1 | Tim Rentsch | |
11 Apr 24 | Re: Recursion, Yo | 2 | Keith Thompson | |
12 Apr 24 | Re: Recursion, Yo | 1 | David Brown | |
14 Apr 24 | Re: Recursion, Yo | 1 | fir | |
10 Apr 24 | Re: Recursion, Yo | 1 | Janis Papanagnou | |
10 Apr 24 | Re: Recursion, Yo | 2 | Kaz Kylheku | |
10 Apr 24 | Re: Recursion, Yo | 1 | David Brown | |
11 Apr 24 | Re: Recursion, Yo | 2 | Lawrence D'Oliveiro | |
12 Apr 24 | Re: Recursion, Yo | 1 | Ben Bacarisse | |
11 Apr 24 | Re: Recursion, Yo | 4 | Lawrence D'Oliveiro | |
11 Apr 24 | Re: Recursion, Yo | 1 | Kaz Kylheku | |
11 Apr 24 | Re: Recursion, Yo | 2 | David Brown | |
11 Apr 24 | Re: Recursion, Yo | 1 | Lawrence D'Oliveiro | |
10 Apr 24 | Re: Recursion, Yo | 1 | Kaz Kylheku | |
10 Apr 24 | Re: Recursion, Yo | 1 | Tim Rentsch | |
9 Apr 24 | Re: Recursion, Yo | 1 | Lawrence D'Oliveiro |
Les messages affichés proviennent d'usenet.