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
How to Throw some light on the splay trees?
Explain how do you view the path?
Why is c platform dependent?
PLS U SENS ME INTERVIEW O. MY EMAIL ADD, SOFIYA.SINGH@GMAIL.COM
Can main () be called recursively?
Explain the Difference between the New and Malloc keyword.
Can we declare a function inside a function in c?
How can I direct output to the printer?
What are logical errors and how does it differ from syntax errors?
How is pointer initialized in c?
What is call by reference in functions?
Explain null pointer.
void main(){ int a; a=1; while(a-->=1) while(a-->=0); printf("%d",a); }
What is #define used for in c?
All technical questions