Write the program to make Permutation(arrangements of string ) of a string .



http://cpp.sh/6tjpq

  some points :-

1_)Permutation :-A permutation is a mathematical technique
     that determines the number of possible arrangements in a set
    when the order of the arrangements matters. 


  
2_) Syntex  :: string.substr(i  , ln  )
      Use of this Syntex:- to make
       substring (i.e make small 
       String from big string).
     i = i represent index.
     ln= ln represent lenth of string
          ex:- let string  a ="abgs";
            cout<<a.substr(0,0)//print nothing lenth is zero
            cout<<a.substr(0,1)//print 'a' because at zero index 'a' is present and length is 1
         
           
#include<iostream>
#include<string>
using namespace std;
 
void permutation(string a,string ans)//user define fuction
{        if(a.size()==0)
           {cout<<ans<<endl;
             return ;}
    
        for(int i=0;i<a.size();i++)
        {    char ch =a[i];
            string ros =a.substr(0,i)+a.substr(i+1);
          //again fuction call : Recursion        
                permutation(ros,ch+ans);
              }        
   }

  int main()
  {
         string a="ABC";
          string b="";

        permutation(a,b);
         return 0;
   }   

Click on the below link and run this program

 http://cpp.sh/6tjpq

    

Comments

Popular posts from this blog

Use of Recursion