Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. String reversal algorithm

String reversal algorithm

Scheduled Pinned Locked Moved Algorithms
algorithms
5 Posts 5 Posters 12 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pita32
    wrote on last edited by
    #1

    Ttt

    K Richard DeemingR 2 Replies Last reply
    0
    • P Pita32

      Ttt

      K Offline
      K Offline
      k5054
      wrote on last edited by
      #2

      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
      done

      while ( isdigit(str[pos2]) and pos1 < pos2 )
      do
      decr pos2
      done

      having 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
      done

      Keep Calm and Carry On

      1 Reply Last reply
      0
      • P Pita32

        Ttt

        Richard DeemingR Offline
        Richard DeemingR Offline
        Richard Deeming
        wrote on last edited by
        #3

        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

        "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

        L 1 Reply Last reply
        0
        • Richard DeemingR Richard Deeming

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Why do you think his moniker starts with "Pita"?

          M 1 Reply Last reply
          0
          • L Lost User

            Why do you think his moniker starts with "Pita"?

            M Offline
            M Offline
            Member_14793535
            wrote on last edited by
            #5

            Good question

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups