Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Answer Posted / rafael christ

#include <iostream>


using namespace std;


char* reverse_str(char* s)
{
char* reverse = new char[1];
//char* reverse;


int i;

if(*s != '\0')
reverse = reverse_str(s+1);

i = strlen(s) - 1;

if (i >= 0)
reverse[i] = s[0];

return reverse;
}


int main(void)
{
char* str = "tsirhc oraivur odraude leafar";


cout << "original:" << endl;
cout << str << endl << endl;

cout << "reversed:" << endl;
cout << reverse_str(str) << endl;

return 0;
}

Is This Answer Correct ?    14 Yes 25 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is %g in c?

1016


The purpose of this exercise is to benchmark file writing and reading speed. This exercise is divided into two parts. a). Write a file character by character such that the total file size becomes approximately >10K. After writing close the file handler, open a new stream and read the file character by character. Record both times. Execute this exercise at least 4 times b). Create a buffer capable of storing 100 characters. Now after generating the characters, first store them in the buffer. Once the buffer is filled up, store all the elements in the file. Repeat the process until the total file size becomes approximately >10K.While reading read a while line, store it in buffer and once buffer gets filled up, display the whole buffer. Repeat the exercise at least 4 times with different size of buffer (50, 100, 150 …). Records the times. c). Do an analysis of the differences in times and submit it in class.

2021


The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none

1187


Read the following data in two different files File A: aaaaaaaadddddddd bbbbbbbbeeeeeeee ccccccccffffffff File B: 11111111 22222222 33333333 By using the above files print the following output or write it in the Other file as follows aaaaaaaa11111111dddddddd bbbbbbbb22222222eeeeeeee cccccccc33333333ffffffffffff

3202


Explain the red-black trees?

1048


Using which language Test cases are added in .ptu file of RTRT unit testing???

4216


List the difference between a "copy constructor" and a "assignment operator"?

956


When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?

994


What is nested structure with example?

1010


What is the process of writing the null pointer?

979


How are strings stored in c?

970


exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

1066


What is the use of typedef in structure in c?

916


What is void pointers in c?

955


Explain function?

1033