Recursive Swapping

This is a discussion on Recursive Swapping within the C Programming forums, part of the General Programming Boards category; I'm writing a recursive program that accepts an input and prints out all n! permutations of the n letters starting ...

  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    9

    Wink Recursive Swapping

    I'm writing a recursive program that accepts an input and prints out all n! permutations of the n letters starting at "a". A permutation of n elements is one of the n! possible orderings of the elements.

    meaning i need to have a sample output like ....

    bca cba cab acb bac abc

    if i enter n=3....

    could anyone help me out on what keywords i should u use ?
    I'm thiniking of doin it wit a resursive program and array swapping ....

    Thanks .... :P

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    a + all permutations of "bc"
    b + all permutations of "ac"
    c + all permutations of "ab"

    The first one them becomes
    b + all permutations of "c"
    c + all permutations of "b"

    All permutations of a single letter are the trivial answer which stops the recursion.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. recursive function
    By technosavvy in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 04:42 AM
  2. difference between recursive and iterative
    By Micko in forum C Programming
    Replies: 33
    Last Post: 07-06-2004, 09:34 PM
  3. Algorithm help (Changing from Recursive to Non Recursive)
    By Thantos in forum C++ Programming
    Replies: 1
    Last Post: 04-25-2004, 07:27 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21