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
What are keywords in c with examples?
What are the types of type specifiers?
What is the difference between the = symbol and == symbol?
hi send me sample aptitude papers of cts?
Write a program to use switch statement.
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
How do you view the path?
Between macros and functions,which is better to use and why?
What is const volatile variable in c?
What are the types of macro formats?
What does sizeof int return?
How do I read the arrow keys? What about function keys?
Explain what are the standard predefined macros?
How do you determine the length of a string value that was stored in a variable?
Draw a flowchart to produce a printed list of all the students over the age of 20 in a class .The input records contains the name and age of students. Assume a sentinel value of 99 for the age field of the trailer record