Thread: what a big work for me!!!

  1. #1
    Registered User
    Join Date
    Sep 2001

    what a big work for me!!!

    Hi, I just tried to display a permuttion of n number, i.e. 1,2,3,4. the I want to disply this permutation
    using C++ code, I just can't figure out the correct algorithum to manupulat it.
    the result should be looks like;
    the total display lines should be 24 (=4!). could some one figure out the algorithum?


  2. #2
    Well, a VERY CRUDE method would be to make a counter that counts from 0 to 9999, and then display only the numbers that match the criteria (i.e. throw-away any results containing a zero or a digit greater than 5, and any results containing duplicate numbers.

    An improvement would be a base-n counter that starts at 1234 and throws-away (or skips) duplicated digits.

  3. #3
    Hardware Engineer
    Join Date
    Sep 2001
    I just realized that if n>9, then you'll HAVE to build your own counter (in an array). There must be a proper algorithm for this(?)

  4. #4
    Join Date
    Aug 2001
    You should be able to use recursion.

  5. #5
    Registered User
    Join Date
    Sep 2001

    Red face

    Actually, I tried to use the recursive method, but I didn't get the correct result, I did try the loop method,I am just confused by how the elements should be exchanged in the array( I use an array to hold the elements), and use the swap function to exchange the elements in each loop.because the result from the total loop(24 for 4 elements) did not generate all the possible permutation.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  2. Problems in getting OpenGL to work
    By zonf in forum C Programming
    Replies: 5
    Last Post: 02-13-2006, 04:48 AM
  3. Constant too big error
    By John_ in forum C++ Programming
    Replies: 5
    Last Post: 01-26-2006, 01:45 AM
  4. Why won't my OpenGL work?
    By Raigne in forum C++ Programming
    Replies: 7
    Last Post: 11-26-2005, 11:53 AM
  5. Developers Wanted
    By Quasicom in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 08-24-2005, 12:46 AM