How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / moinom
#include <iostream>
#include <conio>
void reverse(char a[], int s, int sc );
void reverse(char a[], int s, int sc ){
if ((sc-s)<(s-1))
{
a[sc-s]^=a[s-1];
a[s-1]^=a[sc-s];
a[sc-s]^=a[s-1];
reverse (a, s-1, sc) ;
}
}
void main (){
char a[]="ABCDEFG";
reverse(a, 7, 7);
cout<<a;
getch(); //i just use it to freeze the screen
}
| Is This Answer Correct ? | 14 Yes | 29 No |
Post New Answer View All Answers
Explain how can you restore a redirected standard stream?
How do you initialize pointer variables?
What is structure data type in c?
What are bitwise shift operators in c programming?
Which is best book for data structures in c?
What does malloc () calloc () realloc () free () do?
What is the most efficient way to count the number of bits which are set in an integer?
What is an auto variable in c?
Why do we use c for the speed of light?
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.. :(
What are the 5 elements of structure?
What is an endless loop?
cavium networks written test pattern ..
Explain modulus operator.
Can include files be nested? How many levels deep can include files be nested?