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.

commented: Nice attitude and great guidance +0

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.

my c++ background aint tht good.so i do trial en error can you guide me?

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.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.