How to reverse a string using a recursive function, without
swapping or using an extra memory?
Answer Posted / ozzy
#include <stdio.h>
#include <string.h>
int recreverse (char szStr[], int nSize, int i)
{
// printf ("\n %d - %s ", i, szStr);
if (i < nSize /2)
{
szStr[i] ^= szStr[nSize -(i + 1)];
szStr[nSize -(i + 1)] ^= szStr[i];
szStr[i] ^= szStr[nSize -(i + 1)];
recreverse (szStr, nSize, ++i);
}
else
return;
}
int main()
{
char szStr[256];
int nSize,i;
char cChar;
// int nHash[26] = {0};
// char szDict[26] ="abcdefghijklmnopqrstuvwxyz";
printf("\n Enter the character : ");
// scanf("%s,", szStr);
gets(szStr);
nSize = strlen (szStr);
printf ("\n string %s - %d \n", szStr, nSize);
recreverse (szStr, nSize, 0);
printf ("\n Reverse <<%s>> \n", szStr);
}
Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Write program to remove duplicate in an array?
What is the time and space complexities of merge sort and when is it preferred over quick sort?
What is the use of getch ()?
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 difference between arrays and pointers?
What is the difference between Printf(..) and sprint(...) ?
What is the use of a semicolon (;) at the end of every program statement?
Is it better to use malloc() or calloc()?
What is an example of structure?
c language interview questions & answer
Can you return null in c?
How does struct work in c?
Why do we need volatile in c?
What is Dynamic memory allocation in C? Name the dynamic allocation functions.
i want to switch my career from quailty assurance engineering to development kindly guide me from which programming language its better for me to start plz refer some courses or certifications too i have an experience of 1.5 yrs in QA field.Kindly guide me