How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / smbrd
#include <iostream>
using namespace std;
void rev_str(char* str, int pos=-1, char c='\0'){
if(pos >= int(strlen(str)/2))
return;
if(c != '\0'){
str[strlen(str) - pos - 1] = str[pos];
str[pos] = c;
}
rev_str(str, ++pos, str[strlen(str) - pos - 2]);
}
int main(){
char str[] = "reverse this string";
cout << str << endl;
rev_str(str);
cout << str << endl;
//:~
return 0;
}
| Is This Answer Correct ? | 7 Yes | 15 No |
Post New Answer View All Answers
What is conio h in c?
please help me..... please codes and flowchart plz turbo c lang po yan.....please asap response... 3. Make an astrology program. The user types in his or her birthday (month, day, and year as integer), and the program responds with the user’s zodiac sign, horoscope, and other information related to it. If the user’s birth year falls into a leap year, your program should display an appropriate message for it. NOTES: Conditional Statements: it should be with graphics
What does c mean in basketball?
What is c token?
What 'lex' does?
Differentiate between static and dynamic modeling.
How do we declare variables in c?
how do you programme Carrier Sense Multiple Access
What is function prototype in c with example?
What is the difference between if else and switchstatement
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory
Explain what is the benefit of using #define to declare a constant?
what is recursion in C
i want to know the procedure of qualcomm for getting a job through offcampus
What is function what are the types of function?