/*
* File: heap.c
* Author: cassius
*
* Created on 19 de Novembro de 2006, 22:27
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
static void print_recursive(char* str, int pos, int length)
{
int k;
char first, current;
if(pos >= (length-1) )
fprintf(stdout, "%s ", str);
else
{
first = str[pos];
for(k = pos; k < length; k++)
{
/* swap chars */
current = str[k];
str[pos] = current;
str[k] = first;
print_recursive(str, pos + 1, length);
/* swap it back. */
str[k] = current;
}
str[pos] = first;
}
}
void print(char* str)
{
int len = strlen(str);
print_recursive(str, 0, len);
fprintf(stdout, ".\n");
}
/*
*
*/
int
main(int argc, char** argv) {
char max_str[100];
fprintf(stdout, "Please, digite a word.\n");
fscanf(stdin, "%s ", max_str);
print(max_str);
fprintf(stdout, "Exiting ...");
return (EXIT_SUCCESS);
}
quarta-feira, 22 de novembro de 2006
String character permutation.
Assinar:
Postar comentários (Atom)
Quem sou eu
- Pochemuchka
- I used to work with embedded software and digital design. Now my career is about to turn in a complete different direction ...
Nenhum comentário:
Postar um comentário