Hello.

i am looking for a C++ code that caaculates permutations...for example your input is

abc output should be..

sample output is

abc
cba
bca
cab
acb
bac

its just for revision so a full answer is appreciated...:)

You might appreciate a full answer but we don't appreciate the idea of giving code here in this forum. So write your own program to implement the Jhonson Trotter algorithm or Heap permute algorithm using binary heaps given in A. Levitin, Introduction to The Design & Analysis of Algorithms, Addison Wesley, 2003.

Edited 6 Years Ago by csurfer: n/a

Comments
Nice attitude and great guidance

this is all i could do can you correct me where am wrong i hve manipulated it so much my head is spinning...i was told that i hve to make the user input string of choice....

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int n;
const int ;

void Display(int* iarr)

{
    for(int i=0; i<n; ++i)
        cout<<iarr[i]<<",";
    cout<<endl;
}

int main()
{
cout<<"enter num"<<endl;
cin>>n;


    int iarr[n] = {};

    sort(iarr,iarr+n);
    Display(iarr);
    while(next_permutation(iarr,iarr+n))
        Display(iarr);

    system("pause");

    return 0;
}

I don't see sort or next_permutation functions neither do i see the use of line 7 and the way array is defined in line 23.

Refer to the algorithms I have stated in my first post. And try to implement it as far as you can. Don't worry you will get all the help you need here if you are showing some effort.:)

This article has been dead for over six months. Start a new discussion instead.