CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 17

Threaded View

  1. #13
    Join Date
    Jul 2013
    Posts
    576

    Re: Sorting parallel arrays in C++

    Quote Originally Posted by gwiz01 View Post
    I am not able to get the arrays to sort and match up correctly..
    You don't have to sort to find the min (or max) element of an array.

    You note the first element as the current min candidate. Then you scan the array and for each element check whether it's smaller than the min candidate. If so it becomes the new min candidate. When the scan finishes the min candidate is the smallest element of all.

    So finding min or max can always be done in just one scan of an array. This is not true for sorting (if you find a way just book a ticket to Stockholm to pick up your Nobel prize ) and that's why I can tell right away the "sorting" in findLowest doesn't work. If it seems to it's just accidental luck.

    Finding an extreme element is O(N) whereas sorting is O(N * logN).
    Last edited by razzle; April 6th, 2014 at 04:56 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured