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
Why c is called top down?
Find duplicates in a file containing 6 digit number (like uid) in O (n) time.
Why is c known as a mother language?
a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list
What is the use of a ‘ ’ character?
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
What are pointers? What are different types of pointers?
illustrate the use of address operator and dereferencing operator with the help of a program guys plzzz help for this question
What is the explanation for cyclic nature of data types in c?
How to declare pointer variables?
What does typeof return in c?
find the sum of two matrices and WAP for it.
Which is better malloc or calloc?
What is I ++ in c programming?
What are the benefits of organizational structure?