String reversal algorithm
-
Something like:
let pos1 = first_of(str)
let pos2 = last_of(str)while ( pos1 < pos2 )
do
while ( isdigit(str[pos1]) AND pos1 < pos2 )
do
incr pos1
donewhile ( isdigit(str[pos2]) and pos1 < pos2 )
do
decr pos2
donehaving got here, we know that either
pos1 and pos2 are non-digits, so we can swap them
or pos2 < pos1, which means we are done (while loop will terminate)
if ( pos1 < pos2)
then
swap(str[pos1], str[pos2])
incr pos1
decr pos2
endif
doneKeep Calm and Carry On
-
Editing your message to remove your question after it has been answered is extremely rude. If you think it's going to stop your teacher / boss from finding out that you're cheating on your homework / work, you're sadly mistaken.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Editing your message to remove your question after it has been answered is extremely rude. If you think it's going to stop your teacher / boss from finding out that you're cheating on your homework / work, you're sadly mistaken.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Good question