>>in my application, I defined a linked list just as follows:
>>
[quoted text clipped - 18 lines]
>
> mylist.sort();
Since the data is just an int, std::vector<int> might be a better
container. std::set<int> might even work well depending on what is
being done with the data.
But in general I agree with Carl. Don't create your own linked list (or
any other container) unless there really is no other alternative.
> If you're dead-set against using the C++ standard library, to sort a linked
> list you basically need to use the tehcniques that were used to sort files
> on tapes in decades past. Heapsort and shellsort were both important
> algorithms in that era.
If I remember correctly, heapsort and shellsort both require swapping
and random access, which are problematic for singly linked lists. The
best sort algorithm for a singly linked list is merge sort.

Signature
David Olsen
qg4h9ykc5m@yahoo.com
James Curran - 17 Sep 2004 21:01 GMT
> If I remember correctly, heapsort and shellsort both require swapping
> and random access, which are problematic for singly linked lists. The
> best sort algorithm for a singly linked list is merge sort.
Actually, QuickSort is completely implementable on a Singly-linked list.
The only problem is that you'd need to use the first item on each sublist as
the pivot, so it may succumb to the "nearly-sorted" flaw.

Signature
Truth,
James Curran
Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com
(note new day job!)