started migration stack->tree
This commit is contained in:
48
oper.c
48
oper.c
@@ -2,7 +2,23 @@
|
||||
#include <malloc.h>
|
||||
#include "lceb.h"
|
||||
|
||||
unsigned ncombinations(nops, len)
|
||||
static char *combs[1024]; /* should be dynamic */
|
||||
static int ncombs=0;
|
||||
|
||||
void print_comb(n)
|
||||
int n;
|
||||
{
|
||||
printf("comb %d/%d=[%s]\n", n, ncombs, combs[n]);
|
||||
}
|
||||
void print_combs()
|
||||
{
|
||||
int i;
|
||||
printf("op combs: ");
|
||||
for (i=0; i<ncombs; ++i)
|
||||
printf("%s ", combs[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
static unsigned n_combine(nops, len)
|
||||
int nops, len;
|
||||
{
|
||||
int result = 1;
|
||||
@@ -15,7 +31,7 @@ unsigned ncombinations(nops, len)
|
||||
return result;
|
||||
}
|
||||
|
||||
char *combination(ops, len, n)
|
||||
static char *combine(ops, len, n)
|
||||
char *ops; /* string to combine */
|
||||
int len; /* len of result */
|
||||
int n; /* iteration # */
|
||||
@@ -35,6 +51,30 @@ char *combination(ops, len, n)
|
||||
return res;
|
||||
}
|
||||
|
||||
void gen_combinations(nops)
|
||||
int nops;
|
||||
{
|
||||
char *ops="+-*/";
|
||||
int i, n_combs;
|
||||
int len_ops=strlen(ops);
|
||||
|
||||
n_combs=n_combine(len_ops, nops);
|
||||
printf("gen: n=%d\n", n_combs);
|
||||
for (i=0; i<n_combs; ++i) {
|
||||
combs[ncombs]=strdup(combine(ops, nops, i));
|
||||
ncombs++;
|
||||
}
|
||||
}
|
||||
int n_combs()
|
||||
{
|
||||
return ncombs;
|
||||
}
|
||||
char *nth_comb(n)
|
||||
int n;
|
||||
{
|
||||
return combs[n];
|
||||
}
|
||||
|
||||
#ifdef STANDALONE
|
||||
int main(ac, av)
|
||||
int ac;
|
||||
@@ -45,10 +85,10 @@ int main(ac, av)
|
||||
int i, j, nops, ncombs;
|
||||
|
||||
nops=atoi(*(av+1));
|
||||
ncombs=ncombinations(len_ops, nops);
|
||||
ncombs=n_combine(len_ops, nops);
|
||||
printf("# operators combinations : %d\nlist = ", ncombs);
|
||||
for (i=0; i<ncombs; ++i) {
|
||||
p=combination(ops, nops, i);
|
||||
p=combine(ops, nops, i);
|
||||
printf("[%s]\n", p);
|
||||
//for (j=0; j<4; ++j)
|
||||
// distribute(j, p);
|
||||
|
Reference in New Issue
Block a user