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
1) There is a singing competition for children going to be conducted at a local club. Parents have been asked to arrive at least an hour before and register their children’s names with the Program Manager. Whenever a participant registers, the Program Manager has to position the name of the person in a list in alphabet order. Write a program to help the Program Manager do this by placing the name in the right place each time the Program Manger enters a name. The Logic should be written in Data Structures?
What are examples of structures?
Which is the memory area not included in C program? give the reason
Explain what is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
Explain the difference between exit() and _exit() function?
Is c language still used?
What is "Duff's Device"?
Explain how can I right-justify a string?
What is identifier in c?
How do you print an address?
What is the usage of the pointer in c?
i want to know the procedure of qualcomm for getting a job through offcampus
What is the purpose of 'register' keyword in c language?
Are pointers integer?
Is that possible to store 32768 in an int data type variable?