Click here to Skip to main content
16,011,849 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: General question about MFC app with database support Pin
Beer2626-Jul-03 7:41
Beer2626-Jul-03 7:41 
GeneralWin32 MDI child creation w/ lParam Pin
spoulson26-Jul-03 0:31
spoulson26-Jul-03 0:31 
GeneralRe: Win32 MDI child creation w/ lParam Pin
spoulson29-Jul-03 1:21
spoulson29-Jul-03 1:21 
QuestionFucntion declaration??? Pin
Bob Stanneveld25-Jul-03 23:42
Bob Stanneveld25-Jul-03 23:42 
AnswerRe: Fucntion declaration??? Pin
Andrew Walker26-Jul-03 0:00
Andrew Walker26-Jul-03 0:00 
GeneralRe: Fucntion declaration??? Pin
Bob Stanneveld26-Jul-03 0:03
Bob Stanneveld26-Jul-03 0:03 
GeneralPermutations Pin
doctorpi25-Jul-03 22:20
doctorpi25-Jul-03 22:20 
GeneralRe: Permutations Pin
phlipping25-Jul-03 22:51
phlipping25-Jul-03 22:51 
I don't know about the avioding repetitions part, but here is what I would do:
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <stdlib.h>

typedef void (*FOUND)(char*);

void PermRec(char *str, char *buf, FOUND callback)
{
  int i, n;
  char *buf2;
  if (*str == '\0')
  {
    (*callback)(buf);
    return;
  }
  n = strlen(buf);
  buf2 = malloc(n + 2);
  for (i = 0; i <= n; i++)
  {
    if (i != 0) memcpy(buf2, buf, i);
    buf2[i] = *str;
    if (i != n) memcpy(buf2 + i + 1, buf + i, n - i);
      PermRec(str + 1, buf2, callback);
  }
  free(buf2);
}

void EnumPermutations(char *str, FOUND callback)
{
  PermRec(str, "", callback);
}

void foundone(char *str)
{
  printf("%s\n", str);
}

int main (int argn, char **argv)
{
  if (argn <= 1)
  {
    printf ("Usage:\n  %s <string>\neg:\n  %s 123", argv[0], argv[0]);
    return 1;
  }
  EnumPermutations(argv[1], foundone);
}
eg if called with "123", first it places the 1:
1
then it places the 2 in each of the 2 spots:
21 or 12
then it places the 3 in each of the 3 spots:
321 or 231 or 213, 312 or 132 or 123

what I would probably then do is make it remember in foundone() which permutations it had already recieved, and ignore them if it gets them again.

BTW: there is a "modify" button for when you mess up your post

=====
Phlip

Always proofread carefully to see if you any words out
GeneralRe: Permutations Pin
doctorpi26-Jul-03 20:53
doctorpi26-Jul-03 20:53 
GeneralRe: Permutations Pin
Dudi Avramov27-Jul-03 2:22
Dudi Avramov27-Jul-03 2:22 
Generali guysPermutations Pin
Anonymous25-Jul-03 22:13
Anonymous25-Jul-03 22:13 
GeneralExtended chars in SendInput Pin
phlipping25-Jul-03 21:27
phlipping25-Jul-03 21:27 
GeneralQuestion about stdin under multi-process environment. Pin
George225-Jul-03 19:22
George225-Jul-03 19:22 
GeneralRe: Question about stdin under multi-process environment. Pin
Johnny ²25-Jul-03 21:24
Johnny ²25-Jul-03 21:24 
GeneralRe: Question about stdin under multi-process environment. Pin
George225-Jul-03 21:36
George225-Jul-03 21:36 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns25-Jul-03 23:15
Ryan Binns25-Jul-03 23:15 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 0:58
George226-Jul-03 0:58 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns26-Jul-03 1:01
Ryan Binns26-Jul-03 1:01 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 1:05
George226-Jul-03 1:05 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns26-Jul-03 2:10
Ryan Binns26-Jul-03 2:10 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 2:16
George226-Jul-03 2:16 
GeneralRe: Question about stdin under multi-process environment. Pin
Ryan Binns26-Jul-03 2:38
Ryan Binns26-Jul-03 2:38 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 2:44
George226-Jul-03 2:44 
GeneralRe: Question about stdin under multi-process environment. Pin
Johnny ²26-Jul-03 4:28
Johnny ²26-Jul-03 4:28 
GeneralRe: Question about stdin under multi-process environment. Pin
George226-Jul-03 16:48
George226-Jul-03 16:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.