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. C / C++ / MFC
  4. Reverse array

Reverse array

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
4 Posts 3 Posters 0 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.
  • J Offline
    J Offline
    Johnny Peszek
    wrote on last edited by
    #1

    Hi. I got one dimensional array with integer numbers in it. I want to reverse the numbers. The fisrt number should be last and last should be first e.g. [1,2,3,4,5,6,7,8,9] reverse to [9,8,7,6,5,4,3,2,1]. How can I do it fast? Regards.

    J 1 Reply Last reply
    0
    • J Johnny Peszek

      Hi. I got one dimensional array with integer numbers in it. I want to reverse the numbers. The fisrt number should be last and last should be first e.g. [1,2,3,4,5,6,7,8,9] reverse to [9,8,7,6,5,4,3,2,1]. How can I do it fast? Regards.

      J Offline
      J Offline
      Joaquin M Lopez Munoz
      wrote on last edited by
      #2

      With STL it's simple:

      #include <algorithm>
      ...
      int array[]={1,2,3,4,5,6,7,8,9};
      ...
      std::reverse(array,array+9);

      Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

      L 1 Reply Last reply
      0
      • J Joaquin M Lopez Munoz

        With STL it's simple:

        #include <algorithm>
        ...
        int array[]={1,2,3,4,5,6,7,8,9};
        ...
        std::reverse(array,array+9);

        Joaquín M López Muñoz Telefónica, Investigación y Desarrollo

        L Offline
        L Offline
        Laing James
        wrote on last edited by
        #3

        Hi. The fastest way to 'reverse' the array, would be to traverse it backwards. This requires no copying. James.

        J 1 Reply Last reply
        0
        • L Laing James

          Hi. The fastest way to 'reverse' the array, would be to traverse it backwards. This requires no copying. James.

          J Offline
          J Offline
          Johnny Peszek
          wrote on last edited by
          #4

          Thanks!

          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