Thread: Recursive Swapping

  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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    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.

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, 05: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, 10: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