1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem in Permutations C++

  1. Sep 10, 2008 #1
    I have a serious problem which i am not being able to figure. This program finds all the permutations of a given string using recursion. The diagnostic outputs show that the values of the 'choice' and 'final' character arrays is not maintained at a position (I don't know why). Please help.(marked out in red)

    Code (Text):

    #include <iostream.h>
    #include <conio.h>
    #include <stdio.h>
    #include <string.h>
    using namespace std;

    class Permutation
        static char s[20];
        int width,l;
        void input();
        void compute();
        void recur(char choice[],char final[],int);
    char Permutation::s[20];

    void Permutation::input()                                
      cout<<"Enter the string:";
      cout<<"Places to arrange:";

    void Permutation::compute()
      char s1[20];

    void Permutation::recur(char choice[],char final[],int p)
       int i,j,chk,c=0;
       if(p==width){//base condition
         cout<<"OUT: "<<final;
       //setting choice variables
      //traversing recursion     
        final[p+1]='\0';cout<<"Beforein:\t "<<choice<<" -\t "<<final<<" -\t "<<p+1<<" -\t"<<i+1<<" "<<c<<endl<<endl;
        cout<<"Returned: \t"<<choice<<" - \t"<<final<<" - \t"<<p+1<<"-\t"<<i+1<<" "<<c<<endl<<endl;

    int main()
       Permutation arrange;
       return 0;

  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?
Draft saved Draft deleted

Similar Discussions: Problem in Permutations C++
  1. A C problem (Replies: 3)

  2. C++ problem (Replies: 11)

  3. Problems in C++ (Replies: 5)

  4. A problem with C (Replies: 4)