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

Write a C program linear.c that creates a sequence of processes with a given length. By sequence it is meant that each created process has exactly one child. Let's look at some example outputs for the program. Here the entire process sequence consists of process 18181: Sara@dell:~/OSSS$ ./linear 1 Creating process sequence of length 1. 18181 begins the sequence. An example for a sequence of length three: Sara@dell:~/OSSS$ ./linear 3 Creating process sequence of length 3. 18233 begins the sequence. 18234 is child of 18233 18235 is child of 18234 ........ this is coad .... BUt i could not compleate it .....:( #include #include #include #include int main(int argc, char *argv[]) { int N; pid_t pid; int cont; if (argc != 2) { printf("Wrong number of command-line parameters!\n"); return 1; } N = atoi(argv[1]); printf("Creating process sequence of length %d.\n",N); printf("%d begins the sequence.\n",getpid()); /* What I have to do next ?????? */ }

1609


void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }

1244


What are the features of c language?

611


how to build a exercise findig min number of e heap with list imlemented?

1599


What is the use of typedef in structure in c?

532






What language is c written?

566


difference between object file and executable file

6081


What is variable and explain rules to declare variable in c?

543


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

1724


What is mean by data types in c?

540


What language is windows 1.0 written?

563


pierrot's divisor program using c or c++ code

1717


In cryptography, you could often break the algorithm if you know what was the original (plain) text that was encoded into the current ciphertext. This is called the plain text attack. In this simple problem, we illustrate the plain text attack on a simple substitution cipher encryption, where you know each letter has been substituted with a different letter from the alphabet but you don’t know what that letter is. You are given the cipherText as the input string to the function getwordSets(). You know that a plain text "AMMUNITION" occurs somewhere in this cipher text. Now, you have to find out which sets of characters corresponds to the encrypted form of the "AMMUNITION". You can assume that the encryption follows simple substitution only. [Hint: You could use the pattern in the "AMMUNITION" like MM occurring twice together to identify this]

1948


What are variables c?

602


What is a wrapper function in c?

571