Print all String Permutation Implementation Problem

Question-Given a string containing duplicates, print all its distinct permutations such that there are no duplicate permutations and all permutations are printed in a lexicographic order.

Example-
Input-ABA
Output-
AAB
ABA
BAA

Here is where i took help from-

NOTE–There is also Python and Java implementation code given in description, but i am not familiar with that languages much

It’s algorithm-
1.To maintain a count array of all characters
2.if count is >0 we add that char to our output string and decrement the count
3.if count == len of inp string we print the output string
4.We add the count again to backtrack it

My Implementation-

I don’t know where i am doing wrong in implementation or thinking but it isn’t producing any output.

Please anyone can help?

here is a code you can go through, But it will not produce permutation in lexicographical output.
This can be solved using basic recursion technique

void premutation(string s,int l,int r)
{
if(l==r)
cout<<a<<endl ;
else
{
for(int i=l;i<=r;i++)
{
swap(s[l],s[i]);
permtation(s,l+1,r);
swap(s[l],s[i]); //for backtrack
}

}

}

int main()
{
string s=“ABC”;
int r=s.size();
permutation(s,0,n-1);
return 0;
}

I hope, this code snipet will help you, Anymore suggestion are welcome

i know that approach and i have tried it but it wasn’t giving output in lexicographical order. So i searched on youtube and found this great video. But it has only java and python code given in description so i can’t help myself much comparing correctness of my c++ code.