I wonder if someone answers my question, if somebody tried to use qsort to sort link-list?!!

3. I suppose you could. Though I really don't see the point. Why not just insert in order when you create the list in the first place? I suppose you could have a list that simply [a][pre]ppends the data, and you want to sort it later. But yes, you could use qsort. Remember that with qsort, you're writing your own compare function for it to use. So yeah, you could get it to work. Again, I'm not really sure why you'd want to. I wouldn't. I'd just write a function to sort the list for me. Basicly just reconstruct the list prepending or appending as needed.

Quzah.

4. mergesort is better for list

5. ... and don't forget the standard implementation of qsort is for arrays only.

Skip Lists are pretty neat, if you want an alternative.

6. Originally Posted by Hammer
... and don't forget the standard implementation of qsort is for arrays only.

Skip Lists are pretty neat, if you want an alternative.
That's why you "sort it" into an array of pointers to your nodes.

Quzah.

7. Fair point Kinda defeats the point of having a dynamically sizable list though!

8. Originally Posted by Hammer
Fair point Kinda defeats the point of having a dynamically sizable list though!
Sure, but if you're really fond of qsort...

Quzah.

9. Thanks for all of you,
I tried to implement the approach on the following link ( for Kent):

http://www.experts-exchange.com/Prog..._20754585.html

but I am having problem on the last line(sorted_stocks[index ++] = n of this function

void CopyListToArray(List l)
({
Node *n;
int index;
for(index =0, n =l ; n ; n= n-> next)
sorted_stocks[index ++] = n; //////////here is the problem?!!!
})

compiler displays: [C++ Error] Main.c(518): E2096 Illegal structure operation

10. >E2096 Illegal structure operation
What is sorted_stocks declared as?

11. That is the declaration for n and sorted_stocks:

for sorted_stocks:

//global
typedef struct node
{

Item item;
struct node *next;

}Node;

Node sorted_stocks[MAX_NO_ITEM];

for n (inside CopyListToArry()):

Node *n;

12. You want to either change the statement:
Code:
`sorted_stocks[index ++] = *n;`
Or the declaration of sorted_stocks:
Code:
`Node *sorted_stocks[MAX_NO_ITEM];`
As it is, sorted_stocks[index] is a Node, but n is a pointer to Node. The types do not match.