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
Give differences between - new and malloc() , delete and free() ?
Write a program to input the price of 1 burger and the number of burgers eaten by a group of friends .print the total amount to be paid by the group?
Explain how can you avoid including a header more than once?
how can f be used for both float and double arguments in printf? Are not they different types?
Why isn't any of this standardized in c? Any real program has to do some of these things.
What does typedef struct mean?
What is the purpose of type declarations?
When should volatile modifier be used?
C language questions for civil engineering
What is the purpose of ftell?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
what is the difference between north western polytechnique university and your applied colleges?? please give ur answers for this. :)
provide an example of the Group by clause, when would you use this clause
What is the return type of sizeof?
What is function definition in c?