Urgent!!! Problem in C

I need to make all the permutations of a string's characters........how do i do this.....

tiill now what i was doing was allot a digit to each character.....start from 999999......n times(where n is the no of charcters).......till 0......and then check for digits and print the permutation accordingly....

e.g.: String to be permuted: ajkl
then i was assigning:
1 to a
2 to j
3 to k
4 to l

and looping from 9999 to 0 i was checking for all the numbers which contained the digits 1,2,3,4 and accordingly printed the digit....

Replies

  • Saandeep Sreerambatla
    Saandeep Sreerambatla
    I didnt get you clearly.

    For 4 numbers you have permutations 10000 ??

    Is it what you are doing?
  • silverscorpion
    silverscorpion
    I get what you are saying. You can do it that way, but it is a really inefficient way of doing it.
    You've to replace characters with numbers, do the permutation, and then switch back from numbers to characters.

    Also, it gets very tedious when the string length grows beyond a limit..

    You can easily do this by using pointers and a couple of for loops. Just search for a permutation program in C, and you'll get an idea.
  • Saandeep Sreerambatla
    Saandeep Sreerambatla
    Hey SS, I didnt get the question!

    Can you explain me ?
  • Manish Goyal
    Manish Goyal
    Did you mean to say like this

    say if i the entered string is "abcde" then there must be 120 (=4*3*2*1) different words made by the letters abcde.
    and you want to print out different combination of these characters

    correct me if i am wrong
  • silverscorpion
    silverscorpion
    @Goyal: yes. The question is to print all possible permutations of a string. If it's a 5 character string, then number of permutations will be 5*4*3*2*1 = 120.

    @ES: What I think shashank is doing is this.

    Let's say the string is abc. He'll denote a by 1, b by 2 and c by 3. So, the string is 123 now, and we need the permutations of it.
    What he'll do is, search all numbers from 999 to 0 (actually, it's enough if we search numbers from 999 to 100) and look for numbers that contain all of 1, 2 and 3. He'll probably store these numbers in an array.

    Those numbers will be 123, 132, 213, 231, 312 and 321. Now, these numbers will be in an array. The final step is to replace 1 with a, 2 with b and 3 with c in that array. So, we get all permutations.

    The problem with this is, obviously, with more characters in the string, we need to search more numbers..

You are reading an archived discussion.

Related Posts

I am Wishing a Great Lady Engineer on this special day(Engineers Day). Many More Happy Returns of the day durga! Happy Birthday to you! May you live longer happily with...
I am wishing all our fellow CEans a "Happy Engineers Day" ๐Ÿ˜ The Great Legendary Engineer Bharat Ratna. Mokshagundam Visvesvaraya (1861-1962) was celebrating his Birthday today. I wish him a...
Google has confirmed that it has fired Site Reliability Engineer David Barksdale for accessing users Gtalk and Gmail private data. Google said that the fired employee could use the data...
Twitter's changing its looks and the new looks promises more on every page - [video=youtube;rIpD7hfffQo]https://www.youtube.com/watch?v=rIpD7hfffQo[/video]
why is n-channel MOSFET widely used than p-channel MOSFET?