Reverse a string "in place"

Discussion in 'C Programming' started by Water Cooler v2, Dec 23, 2005.

  1. 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?
     
    Water Cooler v2, Dec 23, 2005
    #1
    1. Advertising

  2. 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.

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Dec 23, 2005
    #2
    1. Advertising

  3. Water Cooler v2

    Skarmander Guest

    Richard Heathfield wrote:
    > 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.
    >

    Badly. Whaet? :)

    S.
     
    Skarmander, Dec 23, 2005
    #3
  4. Skarmander said:

    > Richard Heathfield wrote:
    >> ?ere naem "he qualifier "in placet seod teahW
    >> .
    >> .
    >> .
    >>
    >> I hope you can see how this is going.
    >>

    > Badly. Whaet? :)


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

    --
    Richard Heathfield
    "Usenet is a strange place" - dmr 29/7/1999
    http://www.cpax.org.uk
    email: rjh at above domain (but drop the www, obviously)
     
    Richard Heathfield, Dec 23, 2005
    #4
  5. Water Cooler v2

    Chuck F. Guest

    Water Cooler v2 wrote:
    >
    > 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/>
     
    Chuck F., Dec 23, 2005
    #5
  6. Cool! Thanks a bunch, Richard.
     
    Water Cooler v2, Dec 23, 2005
    #6
  7. Water Cooler v2

    Richard Bos Guest

    Richard Heathfield <> wrote:

    > Skarmander said:
    >
    > > Richard Heathfield wrote:
    > >> ?ere naem "he qualifier "in placet seod teahW
    > >> .
    > >> .
    > >> .
    > >>
    > >> I hope you can see how this is going.
    > >>

    > > Badly. Whaet? :)

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


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

    Richard
     
    Richard Bos, Dec 23, 2005
    #7
  8. Water Cooler v2

    gooch Guest

    Chuck F. wrote:
    > Water Cooler v2 wrote:
    > >
    > > 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.


    Is there even a way you could do it without temporary memory? I can't
    think of one.
     
    gooch, Dec 23, 2005
    #8
  9. Water Cooler v2

    Jordan Abel Guest

    On 2005-12-23, gooch <> wrote:
    >
    > Chuck F. wrote:
    >> Water Cooler v2 wrote:
    >> >
    >> > 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.

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


    You could use the xor trick.
     
    Jordan Abel, Dec 23, 2005
    #9
  10. Water Cooler v2

    Alex Fraser Guest

    "Chuck F. " <> wrote in message
    news:p...
    > Water Cooler v2 wrote:
    > > 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.


    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
     
    Alex Fraser, Dec 23, 2005
    #10
  11. Water Cooler v2

    Chuck F. Guest

    gooch wrote:
    > Chuck F. wrote:
    >> Water Cooler v2 wrote:
    >>>
    >>> 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.

    >
    > 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:
    news:news.announce.newusers
    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
     
    Chuck F., Dec 23, 2005
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Curt_C [MVP]
    Replies:
    0
    Views:
    1,989
    Curt_C [MVP]
    Jan 22, 2004
  2. David Tomlinson
    Replies:
    3
    Views:
    351
  3. dogbite
    Replies:
    4
    Views:
    732
    osmium
    Oct 10, 2003
  4. Reverse a string in place

    , Dec 6, 2007, in forum: C Programming
    Replies:
    30
    Views:
    1,036
  5. ssecorp
    Replies:
    47
    Views:
    1,086
    Default User
    Aug 8, 2008
Loading...

Share This Page