Click here to Skip to main content
15,912,756 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: IPC Thru WM_COPYDATA Pin
leon de boer2-Feb-17 23:45
leon de boer2-Feb-17 23:45 
QuestionThr problem of the recursive algorithm to do binary search in a sorted array Pin
alalba2-Feb-17 15:37
alalba2-Feb-17 15:37 
AnswerRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
Midi_Mick2-Feb-17 16:12
professionalMidi_Mick2-Feb-17 16:12 
GeneralRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
alalba2-Feb-17 16:22
alalba2-Feb-17 16:22 
GeneralRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
alalba3-Feb-17 4:05
alalba3-Feb-17 4:05 
AnswerRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
leon de boer2-Feb-17 23:18
leon de boer2-Feb-17 23:18 
GeneralRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
alalba3-Feb-17 4:25
alalba3-Feb-17 4:25 
GeneralRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
leon de boer3-Feb-17 7:12
leon de boer3-Feb-17 7:12 
No worries can I also give you a much safer option which I always try to teach to new graduates

Don't move the entries at all in the sort. Make yourself an array of pointers to the entries and shuffle your pointers in your private array.

The reasons are obvious
1.) The is no risk of damaging the original data and if you want to undo the function it's instant
2.) On most systems these day an integer is 32bits as is a pointer so it is the same speed to sort them.
3.) For complex types doubles, floats, strings the pointer is a lot smaller than the data.
4.) The source data doesn't have to be in the same place, it can be spread out all over the place the pointers don't care

A common test I set for new employees look like this .. Please write a routine to sort these animals
char* DomesticAnimals[4] = { "Cat", "Dog", "Goat", "Cow" }; // Some domestic animals .. feel free to add some
char* RodentAnimals[4] = { "Mouse", "Rat", "Rabbit", "Fox" };	// Some rodent animals .. feel free to add some
char* WildAnimals[4] = { "Elephant", "Rhino", "Lion", "Tiger"}; // Some wild animals .. feel free to add some,

Basically you copy or move the entries you don't get the job.
The three different source arrays throws most graduates for a loop they feel they have to move something.
Even if they go for an "in place" sort they put wrong animals in wrong categories and they foul my database.

You don't move anything, you make you own private array of char* pointers and point alternate strings and sort whats pointed to with a routine. There are 12 entries above so all you need is
char* myArray[12];

Load each entry to a pointer in that array and sort, and you don't move anything and you don't risk my data if you botch it. This example above sort of makes it very clear why you don't ever move the data .. not ever!

If you want to see the trick of sorting pointers large scale open a windows folder viewer .. what do you think they are doing they don't ever really move or copy the data in anyway it's too risky and slow.

It sorts out those who can program from those who can just write code very quickly.

I would expect a good programmer to be able to write a bubble or quick sort on that array in about 20 lines of code.
Here is the standard Rossetta code for it which is 15 lines
Sorting algorithms/Quicksort - Rosetta Code[^]
In vino veritas


modified 3-Feb-17 13:39pm.

GeneralRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
alalba3-Feb-17 12:46
alalba3-Feb-17 12:46 
SuggestionRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
David Crow3-Feb-17 3:47
David Crow3-Feb-17 3:47 
GeneralRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
alalba3-Feb-17 4:26
alalba3-Feb-17 4:26 
AnswerRe: Thr problem of the recursive algorithm to do binary search in a sorted array Pin
Patrice T8-Feb-17 6:20
mvePatrice T8-Feb-17 6:20 
QuestionStupid build issue - has to be an include file issue.... Pin
charlieg2-Feb-17 15:23
charlieg2-Feb-17 15:23 
AnswerRe: Stupid build issue - has to be an include file issue.... Pin
Peter_in_27802-Feb-17 16:18
professionalPeter_in_27802-Feb-17 16:18 
AnswerRe: Stupid build issue - has to be an include file issue.... Pin
leon de boer2-Feb-17 23:01
leon de boer2-Feb-17 23:01 
GeneralRe: Stupid build issue - has to be an include file issue.... Pin
charlieg3-Feb-17 1:05
charlieg3-Feb-17 1:05 
QuestionLNK2019 unresolved external symbol with Ultimate Toolbox COXTootlTipCtrl and ::MonitorFromRect Pin
Gagnon Claude30-Jan-17 5:02
Gagnon Claude30-Jan-17 5:02 
AnswerRe: LNK2019 unresolved external symbol with Ultimate Toolbox COXTootlTipCtrl and ::MonitorFromRect Pin
Richard MacCutchan30-Jan-17 6:35
mveRichard MacCutchan30-Jan-17 6:35 
GeneralRe: LNK2019 unresolved external symbol with Ultimate Toolbox COXTootlTipCtrl and ::MonitorFromRect Pin
Stefan_Lang30-Jan-17 21:39
Stefan_Lang30-Jan-17 21:39 
GeneralRe: LNK2019 unresolved external symbol with Ultimate Toolbox COXTootlTipCtrl and ::MonitorFromRect Pin
Richard MacCutchan30-Jan-17 22:18
mveRichard MacCutchan30-Jan-17 22:18 
AnswerRe: LNK2019 unresolved external symbol with Ultimate Toolbox COXTootlTipCtrl and ::MonitorFromRect Pin
Member 1489195816-Sep-20 6:40
Member 1489195816-Sep-20 6:40 
QuestionProblem Creating C++ Console App Pin
Kevin Marois27-Jan-17 8:18
professionalKevin Marois27-Jan-17 8:18 
AnswerRe: Problem Creating C++ Console App Pin
Rick York27-Jan-17 8:28
mveRick York27-Jan-17 8:28 
GeneralRe: Problem Creating C++ Console App Pin
Kevin Marois27-Jan-17 8:41
professionalKevin Marois27-Jan-17 8:41 
GeneralRe: Problem Creating C++ Console App Pin
leon de boer27-Jan-17 17:09
leon de boer27-Jan-17 17:09 

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.