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. Ascending order

Ascending order

Scheduled Pinned Locked Moved C / C++ / MFC
questiondata-structures
5 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.
  • I Offline
    I Offline
    iasaber
    wrote on last edited by
    #1

    How can I pass a function that sorts an array of test scores in ascending order?

    J D 2 Replies Last reply
    0
    • I iasaber

      How can I pass a function that sorts an array of test scores in ascending order?

      J Offline
      J Offline
      jhwurmbach
      wrote on last edited by
      #2

      std::sort does sorting. The easy version uses your test scores' operator< for determining sort order. It gets a little more complex if you want to sort by other orders. Or do I misunderstand your question?


      Who is 'General Failure'? And why is he reading my harddisk?!?

      I 1 Reply Last reply
      0
      • J jhwurmbach

        std::sort does sorting. The easy version uses your test scores' operator< for determining sort order. It gets a little more complex if you want to sort by other orders. Or do I misunderstand your question?


        Who is 'General Failure'? And why is he reading my harddisk?!?

        I Offline
        I Offline
        iasaber
        wrote on last edited by
        #3

        dynamicall allocate an array large enough to hold any number of test scores to user wishes to enter. the array should then be passed to a function that sort them in ascending order. I can use std:sort under namespace std; to do that. I thought a num++ or num-- or a if statement? confused on what to do

        J 1 Reply Last reply
        0
        • I iasaber

          dynamicall allocate an array large enough to hold any number of test scores to user wishes to enter. the array should then be passed to a function that sort them in ascending order. I can use std:sort under namespace std; to do that. I thought a num++ or num-- or a if statement? confused on what to do

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          iasaber wrote: I thought a num++ or num-- or a if statement num++/num-- do increase/decrease num. They do not change their position in the array! To do that you need to copy one array member to a local variable, copy the one to exchange to its position and copy your local copy to the position where the other one has been. Dynamical allocation of your array can be done by the STLs std::vector, but I think the point is you learning to handle objects ;-)


          Who is 'General Failure'? And why is he reading my harddisk?!?

          1 Reply Last reply
          0
          • I iasaber

            How can I pass a function that sorts an array of test scores in ascending order?

            D Offline
            D Offline
            David Crow
            wrote on last edited by
            #5

            Have you looked at qsort()?


            Five birds are sitting on a fence. Three of them decide to fly off. How many are left?

            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