START
ESCWYP
MUSIC
VIDEOS
------------------------------------------------- permut.c -----------------------
#include <stdio.h>
#include <stdlib.h>
static int num = 2;
static int index = 0;
static int old = 0;
static int minfree = 0;
static int *f = NULL;
static int *c = NULL;
void freespot(const int ind)
{
if(ind >= 0){
f[ind] = 1;
if(ind < minfree){
minfree = ind;
}
}
}
void takespot(const int ind)
{
if(ind >= 0){
f[ind] = 0;
if(ind == minfree){
int i = 0;
for(i = minfree+1; i < num; ++i){
if(f[i] == 1){
minfree = i;
break;
}
}
}
}
}
void perm()
{
int count = 1;
while(index >= 0){
int start = c[index]+1;
if(start == 0){
start = minfree;
}
int i = start;
for(i; i < num; ++i){
if(f[i] == 1){
freespot(c[index]);
takespot(i);
c[index] = i;
if(index < num-1){
index++;
}else{
freespot(i);
int j = 0;
if(num > 100){
for(j = 0; j < 10; ++j){
fprintf(stdout, "%i ", c[j]);
}
fprintf(stdout, "... ");
for(j = num-10; j < num; ++j){
fprintf(stdout, "%i ", c[j]);
}
}else{
for(j = 0; j < num; ++j){
fprintf(stdout, "%i ", c[j]);
}
}
fprintf(stdout, "| %i\n", count);
count++;
}
break;
}
}
if(index == old){
freespot(c[index]);
c[index] = -1;
index--;
}
old = index;
}
}
int main(int argc, char **argv)
{
if(argc > 1){
num = atoi(argv[1]);
if(num < 2){
num = 2;
}
}
f = malloc(num*sizeof(int));
c = malloc(num*sizeof(int));
int i = 0;
for(i = 0; i < num; ++i){
c[i] = -1;
f[i] = 1;
}
fprintf(stdout, "Init fertig %i\n", num);
perm();
return 0;
}
START
ESCWYP
MUSIC
VIDEOS