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

sorting

Scheduled Pinned Locked Moved C / C++ / MFC
algorithmsdata-structuresquestion
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.
  • R Offline
    R Offline
    RockyJames
    wrote on last edited by
    #1

    hi.. i have an array of data i want to sort the data linearly..is there any way to do it..?

    S 1 Reply Last reply
    0
    • R RockyJames

      hi.. i have an array of data i want to sort the data linearly..is there any way to do it..?

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      Use std::sort from the STL. For example to sort an array of ints: int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5}; int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]); std::sort(NumArray, pNumOnePartEnd); Remember to #include <algorithm>. Steve

      R 1 Reply Last reply
      0
      • S Stephen Hewitt

        Use std::sort from the STL. For example to sort an array of ints: int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5}; int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]); std::sort(NumArray, pNumOnePartEnd); Remember to #include <algorithm>. Steve

        R Offline
        R Offline
        Roland Pibinger
        wrote on last edited by
        #3

        Stephen Hewitt wrote:

        int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
        int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]);
        std::sort(NumArray, pNumOnePartEnd);

        should probably be pNumOnePastEnd ;)

        S 1 Reply Last reply
        0
        • R Roland Pibinger

          Stephen Hewitt wrote:

          int NumArray[] = {3, 1, 4, 1, 5, 9, 2, 6, 5};
          int *pNumOnePartEnd = NumArray + sizeof(NumArray)/sizeof(NumArray[0]);
          std::sort(NumArray, pNumOnePartEnd);

          should probably be pNumOnePastEnd ;)

          S Offline
          S Offline
          Stephen Hewitt
          wrote on last edited by
          #4

          Yes, I did mean to write "one past the end". Note however that I made the mistake consistently so the example would still work. Steve

          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