LinuxQuestions.org
Help answer threads with 0 replies.
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 10-11-2011, 04:12 AM   #16
ArthurSittler
Member
 
Registered: Jul 2008
Distribution: Slackware
Posts: 124

Rep: Reputation: 31
function pointers in C abstract data from algorithm


Function pointers in C are essential to abstract data type from algorithm. An example is the sort() function. It performs an in-place sort of an array. The best algorithm for sorting directory names or data points on a two-dimensional graph or any other sort of thing is the same algorithm. The sort algorithm needs some comparison function to decide if one object is "larger" than another of the same type. The comparison function for file names is very different from the comparison function for data points. Both functions can return a simple int result, however. The sort algorithm chooses two array elements for each comparison. The sort function passes the pointers to the two array elements to the compare function. Depending on the result of the comparison, the sort function may swap the two compared elements. Then the sort function goes on to choose the next two elements for comparison and so on until the array is sorted. The sort function library routine needs the address of the array of elements, the number of elements in the array, and a function pointer to the compare function.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Function pointers with variable arguments kvm1983 Programming 3 07-14-2011 10:12 PM
Using C function pointers in C++ Hexstatic Programming 3 09-26-2006 05:58 PM
Matrix of function pointers kvtournh Programming 9 03-20-2006 04:38 AM
Function pointers, calling, and templates The_Nerd Programming 2 10-09-2005 07:08 PM
Function pointers in C. Matir Programming 2 03-15-2005 03:10 PM

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

All times are GMT -5. The time now is 03:01 AM.

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