Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Sorting arrays.

Author
Message
theagg
16
Years of Service
User Offline
Joined: 11th Feb 2008
Location:
Posted: 15th Feb 2008 16:44
If I am to follow the advice of the 'professionals' its best not to try to write ones own sort arrays but instead use the 'sort' function that comes in the standard library.

However, following this advice, I cannot get it to work.

I have ensured that #include <algorithm> is placed in the header section ( in which the 'sort' function resides supposedly ) but this still results in a compilation error as follows when the sort function is used as here

#include <algorithm>
using namespace std;

.....//

array[n]= {numbers added to array etc };

.....//

sort ( array, array + n )

--------------------------------

error..

1>libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z)
1>Debug\Dark GDK - Game1.exe : fatal error LNK1120: 1 unresolved externals
---------------------------------

Any suggestions as to why the call to the sort function is giving the compilation error ?
Jack LOL
18
Years of Service
User Offline
Joined: 4th Aug 2006
Location: Near the CPU Close to the graphic card
Posted: 17th Feb 2008 09:20 Edited at: 17th Feb 2008 09:23
Well usually that happens when you don't link something correctly.

Add that after the #include directive.

Also if that doesn't solve the problem try this code:
http://www.cplusplus.com/reference/algorithm/sort.html


jason p sage
17
Years of Service
User Offline
Joined: 10th Jun 2007
Location: Ellington, CT USA
Posted: 17th Feb 2008 13:44
I don't buy the Mainstream suggestions - like not making your own sorting routines (all the time) there are definate reasons why people say this. I also know writing your own sorting routines is a good learning exercise.

Depending on the sort you wish to accomplish - there are various ways to do it "Faster" than bubble sort - but frankly - bubble sort - though not the fastest - might be all you need.

Another one that I think is actually fun to write is when you have a list of integers - and this list is in the range of the array size - you do (dunno real name) halving... Where rather then check every location - you check if the value falls above or below the middle mark. Then you do the same in the "Half" of the array you just determined the value should go - then again. (This might not make sense from what I'm saying but...)

In short - Linker Errors? Yes they are a pain. You should know how to use STDLIB if possible ...sure.

Not write your routines? BAH - I think we all should try are hand at home dynamic arrays, double linked lists, sorting algorythms, scripting/compilers etc... it helps make you a better coder and helps you understand what other people likely did in the libraries you may call - such as stdlib! Keep At it man!

Login to post a reply

Server time is: 2024-11-20 01:23:00
Your offset time is: 2024-11-20 01:23:00