How to reverse a string using a recursive function, without
swapping or using an extra memory?

Answer Posted / osama al-ahmad

#include <iostream>
#include < string >
using namespace std;
int i=0;
int z=0;
int count=0;
int Length(string name)
{
if (name[i] == '\0')
return count;
else
{
count++;
i++;
return Length(name);
}

}
char Print_B(string name)
{
if (z == Length(name))
return name[z];
else
{
z++;
cout<<name[count];
count--;
return Print_B(name);
}
}
void main()
{
string name;
cin>>name;
cout<<"Name : ";
Length(name);
cout<<Print_B(name);
}

Is This Answer Correct ?    4 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do c compilers work?

787


What is a dynamic array in c?

793


What is s or c?

783


Which are low level languages?

832


How can I manipulate individual bits?

784


What are all different types of pointers in c?

763


How do you initialize pointer variables?

790


What is the purpose of realloc()?

869


How do you override a defined macro?

890


Why & is used in c?

910


How can I open files mentioned on the command line, and parse option flags?

794


Can we change the value of constant variable in c?

791


What functions are in conio h?

876


What are the features of c languages?

817


Explain pointer. What are function pointers in C?

815