Reverse a string "in place"

W

Water Cooler v2

I've asked myself this question in the past but couldn't afford more
time to it (I program other languages for my bread and butter), so I'll
ask now since it's never too late.

What does the qualifier "in place" mean here? Does that mean without
using additional memory?
 
R

Richard Heathfield

Water Cooler v2 said:
I've asked myself this question in the past but couldn't afford more
time to it (I program other languages for my bread and butter), so I'll
ask now since it's never too late.

What does the qualifier "in place" mean here? Does that mean without
using additional memory?

What does the qualifier "in place" mean here?
?hat does the qualifier "in place" mean hereW
?eat does the qualifier "in place" mean herhW
?ert does the qualifier "in place" mean heahW
?ere does the qualifier "in place" mean teahW
?ere does the qualifier "in place" mean teahW
?ere noes the qualifier "in place" mead teahW
?ere naes the qualifier "in place" meod teahW
?ere naes the qualifier "in place" meod teahW
?ere naem the qualifier "in place" seod teahW
?ere naem the qualifier "in place" seod teahW
?ere naem "he qualifier "in placet seod teahW
.
.
.

I hope you can see how this is going.
 
S

Skarmander

Richard said:
Water Cooler v2 said:




What does the qualifier "in place" mean here?
?hat does the qualifier "in place" mean hereW
?eat does the qualifier "in place" mean herhW
?ert does the qualifier "in place" mean heahW
?ere does the qualifier "in place" mean teahW
?ere does the qualifier "in place" mean teahW
?ere noes the qualifier "in place" mead teahW
?ere naes the qualifier "in place" meod teahW
?ere naes the qualifier "in place" meod teahW
?ere naem the qualifier "in place" seod teahW
?ere naem the qualifier "in place" seod teahW
?ere naem "he qualifier "in placet seod teahW
.
.
.

I hope you can see how this is going.
Badly. Whaet? :)

S.
 
C

Chuck F.

Water said:
I've asked myself this question in the past but couldn't afford
more time to it (I program other languages for my bread and
butter), so I'll ask now since it's never too late.

What does the qualifier "in place" mean here? Does that mean
without using additional memory?

Almost. It means returning the result in the same storage in which
it arrived. This doesn't prevent using temporary auxiliary memory.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
More details at: <http://cfaj.freeshell.org/google/>
 
R

Richard Bos

Richard Heathfield said:
Skarmander said:


I *knew* I should have written code to do that. (sigh)

Yeah, every Anglo-Saxon fule noes that that should be "Hwaet!".

Richard
 
G

gooch

Chuck said:
Almost. It means returning the result in the same storage in which
it arrived. This doesn't prevent using temporary auxiliary memory.

Is there even a way you could do it without temporary memory? I can't
think of one.
 
A

Alex Fraser

Chuck F. said:
Almost. It means returning the result in the same storage in which
it arrived. This doesn't prevent using temporary auxiliary memory.

But "in place" is usually taken to mean "with *constant* additional memory",
ie the amount of "temporary auxialliary memory" cannot depend on the length
of the string.

Alex
 
C

Chuck F.

gooch said:
Is there even a way you could do it without temporary memory? I
can't think of one.

Yes. It depends on the fact that a C string cannot contain '\0'.
It is not recommended. The implementation is left as an exercise.

(BTW, this does not eliminate the need for counters, etc.)

--
Some informative links:
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top