string permutation

i want to display all the possible strings that can be made out of a given string(string doesn't contains repititive letters),can any1 help me out using C.


  • Hey actually the same question I asked over the same forum, mey be last year and I implemented that program successfully.
    Presently I am not having that code, or I should say the code is misplaced.
    So, whenever I got the code I will post it over the same thread.

    Untill you can refer from [link=]here[/link].

  • okay forget the above post...I do not found the code...

    I am going to give the Idea about that code...

    suppose you want to create all combinations of string 'abcde'

    declare the string globally.

    your one function will print two strings.
    1. string
    2. string obtained by swapping last two characters of strings.

    Now make as many functions with name levels as level_1(),level_2(),level_3() and so on, according to range of characters in your string.

    you will need to set the pointer at each level to identify the postion at the string for the particular function.

    pass your string from each level in a sequnce from 5 to 1.
    at each level store corresponding values of pointer.
    Say at level 5 you can take i = 0,
    level 4 you can take i = 1,.........

    As the string crosses each level, and reaches the level 1,
    in the level_1 function you can call some other function say work()
    to print the
    1. string and
    2. string obtained by swapping last two characters of strings.
    I mean work() contain a function called swap(), for swapping last two chracters.

    NOW SEE,,,code is about to print the values as...


    now pass the control to the level_1 that will arrange the string in suchh a way.... 'abdce'
    Remember level_1 will perform this operation on reaching it for the second time. so you will have to pick the value of pointer in such a way, so that funtion will recognize that it is going to be called for the second time.

    then it will type two more strings as:

    'abdce' and 'abdec'

    after completion of that cycle in such a way, function will transfer control to higher levels. and the same rearranging will take place.

    ie. at level_2 abcde will be rearranged as acbde -> adbce -> aebcd.
    at one more higher level you will arrange b to first position and further writing will occur.

    Here, for the range of 5 characters you will be required to make 5 levels
    as your Range will of functions will increase.
    so for improving this method...we should try for the 'recursion'.

    If you understand, whatever I explained then implement this and try to achieve it through recursion.
    If not then, whenever I will feel free I'll write it and give you the exact code.

    Reply in both the conditions... I need the feedback for this.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion