GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 15-Feb-2007, 08:46
mathematician mathematician is offline
Member
 
Join Date: Nov 2006
Location: Shrewsbury Uk
Posts: 133
mathematician will become famous soon enough

Re: sort an array of structures


First you said I had to allocate the structs contiguously. That was the thing that made me confused. But in the second point, you said that the things the pointers point to will not necessarily be in contiguous blocks...

It would have been easier to allocate the structs continuously, because then you would have been able to sort them directly, instead of sorting pointers to pointers.


(But when thinking more of it, if that not had been the case, why should one then need to give the size argument to qsort?)

qsort needs to know the size of the objects it is moving around. It has no way of knowing whether they are pointers, structures, or anything else. So far as it is concerned they are just blocks of memory it is being asked to sort, and it needs to know how large those blocks are.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
printing an array of structures nic.nmd C Programming Language 3 19-Oct-2006 08:53
Need help deleting the last element in the array headphone69 C++ Forum 2 15-Mar-2006 20:31
Merge and Heap...which is really faster silicon C++ Forum 0 10-May-2005 14:46
Sorting Algorithms by Time silicon C++ Forum 4 02-May-2005 22:54
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 22:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:48.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.