Answer the question
In order to leave comments, you need to log in
C iterative algorithm and recursion. Implementation of recursion Who knows?
Display vowel sentences in direct and reverse order. In one program, complete the task in two versions: using an iterative algorithm and using recursion. C
Look right?
#include <stdio.h>
void reverse(char* begin, char* end);
void reverseWords(char* s)
{
char* word_begin = s;
char* temp = s; /* temp is for word boundry */
while (*temp) {
temp++;
if (*temp == '\0') {
reverse(word_begin, temp - 1);
}
else if (*temp == ' ') {
reverse(word_begin, temp - 1);
word_begin = temp + 1;
}
}
reverse(s, temp - 1);
}
void reverse(char* begin, char* end)
{
char temp;
while (begin < end) {
temp = *begin;
*begin++ = *end;
*end-- = temp;
}
}
/* Driver function to test above functions */
int main()
{
char s[] = "i like this program very much";
char* temp = s;
reverseWords(s);
printf("%s", s);
getchar();
return 0;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question