The problem is to delete adjacent pair of identical alphabets until there is no such pair. I have used recursion for this. But the code gives Segmentation fault. What is wrong with this recursion?
#include<iostream>
#include<string>
using namespace std;
string super(string s)
{
for(int i=0;i<s.length();i++)
{
if(s[i]==s[i+1])
{
s.erase(s.begin()+i);
s.erase(s.begin()+i+1);
s=super(s);
cout<<s;
break;
}
if(i+1==s.length())
return s;
}
return s;
}
int main()
{
string s;
cin>>s;
s=super(s);
if(s.length()<0)
cout<<s;
else
cout<<"Empty String";
}
if(s.length()<0) cout<<s;s.erase(s.begin() + i), the character that used to be ass.begin() + i + 1is now ats.begin() + i.