Reverse a string "in place"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Water Cooler v2

    #1

    Reverse a string "in place"

    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?

  • Richard Heathfield

    #2
    Re: Reverse a string "in place"

    Water Cooler v2 said:
    [color=blue]
    > 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?[/color]

    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

    Comment

    • Skarmander

      #3
      Re: Reverse a string "in place"

      Richard Heathfield wrote:[color=blue]
      > Water Cooler v2 said:
      >
      >[color=green]
      >>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?[/color]
      >
      >
      > 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.
      >[/color]
      Badly. Whaet? :-)

      S.

      Comment

      • Richard Heathfield

        #4
        Re: Reverse a string "in place"

        Skarmander said:
        [color=blue]
        > Richard Heathfield wrote:[color=green]
        >> ?ere naem "he qualifier "in placet seod teahW
        >> .
        >> .
        >> .
        >>
        >> I hope you can see how this is going.
        >>[/color]
        > Badly. Whaet? :-)[/color]

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

        --
        Richard Heathfield
        "Usenet is a strange place" - dmr 29/7/1999

        email: rjh at above domain (but drop the www, obviously)

        Comment

        • Water Cooler v2

          #5
          Re: Reverse a string "in place"

          Cool! Thanks a bunch, Richard.

          Comment

          • Richard Bos

            #6
            Re: Reverse a string "in place"

            Richard Heathfield <invalid@invali d.invalid> wrote:
            [color=blue]
            > Skarmander said:
            >[color=green]
            > > Richard Heathfield wrote:[color=darkred]
            > >> ?ere naem "he qualifier "in placet seod teahW
            > >> .
            > >> .
            > >> .
            > >>
            > >> I hope you can see how this is going.
            > >>[/color]
            > > Badly. Whaet? :-)[/color]
            >
            > I *knew* I should have written code to do that. (sigh)[/color]

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

            Richard

            Comment

            • Chuck F.

              #7
              Re: Reverse a string &quot;in place&quot;

              Water Cooler v2 wrote:[color=blue]
              >
              > 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?[/color]

              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.c om, 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/>

              Comment

              • gooch

                #8
                Re: Reverse a string &quot;in place&quot;


                Chuck F. wrote:[color=blue]
                > Water Cooler v2 wrote:[color=green]
                > >
                > > 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?[/color]
                >
                > Almost. It means returning the result in the same storage in which
                > it arrived. This doesn't prevent using temporary auxiliary memory.[/color]

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

                Comment

                • Jordan Abel

                  #9
                  Re: Reverse a string &quot;in place&quot;

                  On 2005-12-23, gooch <gooch001@comca st.net> wrote:[color=blue]
                  >
                  > Chuck F. wrote:[color=green]
                  >> Water Cooler v2 wrote:[color=darkred]
                  >> >
                  >> > 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?[/color]
                  >>
                  >> Almost. It means returning the result in the same storage in which
                  >> it arrived. This doesn't prevent using temporary auxiliary memory.[/color]
                  >
                  > Is there even a way you could do it without temporary memory? I can't
                  > think of one.[/color]

                  You could use the xor trick.

                  Comment

                  • Alex Fraser

                    #10
                    Re: Reverse a string &quot;in place&quot;

                    "Chuck F. " <cbfalconer@yah oo.com> wrote in message
                    news:pY-dnTJJK5twWDbenZ 2dnUVZ_tudnZ2d@ maineline.net.. .[color=blue]
                    > Water Cooler v2 wrote:[color=green]
                    > > 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?[/color]
                    >
                    > Almost. It means returning the result in the same storage in which
                    > it arrived. This doesn't prevent using temporary auxiliary memory.[/color]

                    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


                    Comment

                    • Chuck F.

                      #11
                      Re: Reverse a string &quot;in place&quot;

                      gooch wrote:[color=blue]
                      > Chuck F. wrote:[color=green]
                      >> Water Cooler v2 wrote:[color=darkred]
                      >>>
                      >>> 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?[/color]
                      >>
                      >> Almost. It means returning the result in the same storage in
                      >> which it arrived. This doesn't prevent using temporary
                      >> auxiliary memory.[/color]
                      >
                      > Is there even a way you could do it without temporary memory? I
                      > can't think of one.[/color]

                      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.annou nce.newusers
                      Latest news coverage, email, free stock quotes, live scores and video are just the beginning. Discover more every day at Yahoo!





                      Comment

                      Working...