LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-20-2023, 04:37 AM   #16
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,453

Rep: Reputation: 447Reputation: 447Reputation: 447Reputation: 447Reputation: 447

Also, qsort has a friend called bsearch.

If you look at the example here:

https://man7.org/linux/man-pages/man3/bsearch.3.html

First the array is sorted by name. Then bsearch is used for lookup. If the array had millions, using bsearch is a lot faster, because it doesn't have to search through the entire array. And the comparison function is the same.
 
1 members found this post helpful.
Old 06-21-2023, 01:58 AM   #17
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,866
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Off: for learners, it would be an interesting exercise to find the missing features in bsearch(3)
For example the lack of user-parameter in callback (compare qsort(3) and qsort_r(3))
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
qsort vs 'Magnetica' Quicksort Sanmayce Programming 19 10-09-2022 01:19 AM
Can't set signature algorithm when using tpm2_import : Signature algorithm is null with error hash avertyr Linux - Software 2 05-23-2022 02:21 AM
[SOLVED] MD5 Algorithm Implementation gfmtech05 Programming 3 04-28-2011 08:06 AM
implementation of RSA algorithm in C / C++ rupa sarda Programming 1 08-02-2010 11:12 AM
token bucket algorithm vs Leaky bucket algorithm xeon123 Linux - Networking 2 03-26-2007 04:57 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:29 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration