c - What is the time complexity of my codes: reversing words in a string? Should I account for asymmetrical spacing? -
problem statement : write function of declaration void str_words_in_rev(char *input, int length) reverses words in string of word/(s). i've implemented 2 different solutions it, 1 of extremely complicated. solution 1: reverse entire string using void reverse(char* string, int start, int end) function takes index of first , last letter of string or substring want reverse. after that, reverse each word in string using same reverse function. #include<stdio.h> void swapchar(char *a, char *b) { char temp = *a; *a = *b; *b = temp; } int length(char *string) { if(string == null) return -1; int i=0; for(;string[i++];); return i; } void reverse(char* string, int start, int end) { int mid = start + (end - start + 1)/2; for(int i=start,j=end;i<mid;) swapchar(&string[i++], &string[j--]); } int main() { char str[] = "abc def ghij klmn"; int i=0, j=0, len = length(str), flag = 0; if(str == null || !(*str)) return 0...