Click here to Skip to main content
15,889,651 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerUse QuickSort Pin
DarthDana24-Nov-10 4:20
professionalDarthDana24-Nov-10 4:20 
GeneralRe: Use QuickSort Pin
Maximilien24-Nov-10 5:42
Maximilien24-Nov-10 5:42 
GeneralRe: Use QuickSort Pin
Matthew Barnett24-Nov-10 5:46
Matthew Barnett24-Nov-10 5:46 
GeneralRe: Use QuickSort Pin
«_Superman_»24-Nov-10 7:30
professional«_Superman_»24-Nov-10 7:30 
GeneralRe: Use QuickSort Pin
ThatsAlok11-Jul-11 21:18
ThatsAlok11-Jul-11 21:18 
AnswerRe: Sort Functions Pin
James Lonero24-Nov-10 9:00
James Lonero24-Nov-10 9:00 
AnswerRe: Sort Functions Pin
dpminusa24-Nov-10 13:32
dpminusa24-Nov-10 13:32 
AnswerRe: Sort Functions Pin
James Curran28-Nov-10 5:18
James Curran28-Nov-10 5:18 
The first one (sort()), scans the list to find the smallest item (it assumes that elemType has operator<() defined, which we presume is bases on it's ticker symbol string). It then swaps that items with the item in list[0]. Next it scans for the smallest between list[1] and the end, and swaps that with list[1], and onward, swapping the smallest among list[2] & the end with list[2]. I believe this actually makes it an insertion sort, which is slightly faster that a bubble sort (and generally considered the best for small lists)

The second sort (sortByGain()) doesn't want to change the order of the items in list (which presumably have just been sorted by sort()), so it creates a array of indexes into list, so that after both functions are called list[0] is the first stock alphabetically, while list[indexByGain[0]] is the stock with the highest gain.

sortByGain() does a proper (slow) Bubble sort, potenially swapping after every compare, moving the desired item (which is the smallest in the first sort and the largest in the second) one position closer to it's final location each time.
Truth,
James

QuestionCButton question Pin
DerrekCurtis23-Nov-10 7:09
DerrekCurtis23-Nov-10 7:09 
AnswerRe: CButton question Pin
«_Superman_»23-Nov-10 7:19
professional«_Superman_»23-Nov-10 7:19 
AnswerRe: CButton question Pin
Member 399486624-Nov-10 3:13
Member 399486624-Nov-10 3:13 
QuestionDebugging multiple processes within a visual studio solution Pin
aevanscambs23-Nov-10 6:00
aevanscambs23-Nov-10 6:00 
AnswerRe: Debugging multiple processes within a visual studio solution Pin
Eugen Podsypalnikov23-Nov-10 6:02
Eugen Podsypalnikov23-Nov-10 6:02 
AnswerRe: Debugging multiple processes within a visual studio solution Pin
«_Superman_»23-Nov-10 7:16
professional«_Superman_»23-Nov-10 7:16 
QuestionListing DLL Exports Pin
softwaremonkey23-Nov-10 5:23
softwaremonkey23-Nov-10 5:23 
AnswerRe: Listing DLL Exports PinPopular
Eugen Podsypalnikov23-Nov-10 5:54
Eugen Podsypalnikov23-Nov-10 5:54 
GeneralRe: Listing DLL Exports Pin
softwaremonkey23-Nov-10 6:09
softwaremonkey23-Nov-10 6:09 
AnswerRe: Listing DLL Exports Pin
«_Superman_»23-Nov-10 7:21
professional«_Superman_»23-Nov-10 7:21 
AnswerRe: Listing DLL Exports Pin
Luc Pattyn23-Nov-10 8:23
sitebuilderLuc Pattyn23-Nov-10 8:23 
QuestionPutting CMFCToolBar in CFormView problem Pin
Harsh Shankar23-Nov-10 1:13
Harsh Shankar23-Nov-10 1:13 
AnswerRe: Putting CMFCToolBar in CFormView problem Pin
Eugen Podsypalnikov23-Nov-10 5:45
Eugen Podsypalnikov23-Nov-10 5:45 
QuestionRe: Putting CMFCToolBar in CFormView problem Pin
Harsh Shankar24-Nov-10 2:54
Harsh Shankar24-Nov-10 2:54 
AnswerRe: Putting CMFCToolBar in CFormView problem Pin
Eugen Podsypalnikov24-Nov-10 21:42
Eugen Podsypalnikov24-Nov-10 21:42 
QuestionRequired resource [modified] Pin
MsmVc22-Nov-10 22:59
MsmVc22-Nov-10 22:59 
AnswerRe: Required resource Pin
Richard MacCutchan22-Nov-10 23:34
mveRichard MacCutchan22-Nov-10 23:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.