What are the different ways to reverse a string?
- Fastest Way - Least space
this is the fastest way.. i think ========================
void reverse(char *s) { int t; char *a; a = s + (strlen(s)-1); printf("the address is :%x\n",a); for( ; s < a ; s++,a--) { t = *s; *s = *a; *a = t; } }
i can code it with O(n/2) complexity. Is any faster algo possible? No additional memory is needed for reversing except a cgaracter for swapping.
Reverse a string?
this is the fastest way.. i think
========================
void reverse(char *s)
{
int t;
char *a;
a = s + (strlen(s)-1);
printf("the address is :%x\n",a);
for( ; s < a ; s++,a--)
{
t = *s;
*s = *a;
*a = t;
}
}
Reverse a string?
i can code it with O(n/2) complexity.
Is any faster algo possible? No additional memory is needed for reversing except a cgaracter for swapping.