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. sort structures

sort structures

Scheduled Pinned Locked Moved C / C++ / MFC
data-structuresquestionlearning
4 Posts 4 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.
  • K Offline
    K Offline
    kerrywes
    wrote on last edited by
    #1

    = per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?

    C J G 3 Replies Last reply
    0
    • K kerrywes

      = per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      kerrywes wrote:

      per[x+1] = *temp;

      that doesn't seem right. shouldn't it be "per[x+1]=temp;" i assume per is an array of pointers to PERSONs Cleek | Image Toolkits | Thumbnail maker

      1 Reply Last reply
      0
      • K kerrywes

        = per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?

        J Offline
        J Offline
        Joe Woodbury
        wrote on last edited by
        #3

        gets just a pointer but then per[x] = per[x+1] does a copy, destroying the original data. You need to force copies for each of the swap operations. You also need to make temp a value, not a pointer. temp = per[x]; per[x] = per[x+1]; per[x+1] = temp; Ultimately, this realy doesn't do a sort, though. It just does a single pass through the array. Look up bubble sort to learn how to do a very basic sort. (Generally, using qsort, or some version thereof, would be better.) Anyone who thinks he has a better idea of what's good for people than people do is a swine. - P.J. O'Rourke

        1 Reply Last reply
        0
        • K kerrywes

          = per[x+1]; per[x+1] = *temp; } } } the results are not right, duplicated entries and other oddness, whats wrong?

          G Offline
          G Offline
          Ghasrfakhri
          wrote on last edited by
          #4

          kerrywes wrote:

          = per[x+1]; 5. per[x+1] = *temp; 6. }

          but replace the content of that ! must change to
          = per[x+1]; per[x+1] = *temp; }
          but in this case you have a problem that the temp is pointer, you most declere it as PERSON temp; Iman Ghasrfakhri -- modified at 1:12 Sunday 30th October, 2005

          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