[Interest] qsort() Obsolete?

Bo Thorsen bo at vikingsoft.eu
Fri Apr 17 14:17:23 CEST 2015


On 04/17/2015 12:12 PM, Berkay Elbir wrote:
> Hello All,
>
> I want to ask a question to you to be certain. Is void qsort() function
> obsolete? Should we use std::sort instead of this function? Because I
> have a priority list and need to sort it.

Slightly off-topic: Don't implement a priority queue this way. Unless 
you have a system where you get a bunch of those and can sort them once, 
and handle all of them. If this isn't the case, you are going to have 
inserts and removes mixed. Then you will continually sort something 
that's already sorted.

I have an old implementation of a priority queue you can use instead. 
It's an implementation of a binary heap algorithm. It's optimized for 
the case where there are just a few items in the queue and very rarely 
it will get a burst of more. If your case doesn't match this, you could 
probably remove the resize to minimum. You can instantiate it with 
anything that implements operator<.

I hope it helps.

Bo Thorsen,
Director, Viking Software.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: priorityqueue.h
Type: text/x-chdr
Size: 3041 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150417/361b73ce/attachment.h>


More information about the Interest mailing list