|
-
Oct 20th, 2002, 03:19 AM
#1
Thread Starter
New Member
Smallest iteam using Link list
Hi there;
if I have a link list and I want to get the smallest item. How to make that algorithm.
teach yourself as you can, when you get stuck ask and do not shy
-
Oct 20th, 2002, 03:52 AM
#2
Monday Morning Lunatic
If the list is sorted, just pick either the tail or the head depending on how you sorted it.
If it's unsorted, you have to use a linear search (i.e. just go through each node and check).
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 20th, 2002, 08:13 AM
#3
Thread Starter
New Member
this is the point:
how to check, using strcmp is enough or should I use any other way to get the smallest item.
note: the list is not sorted
teach yourself as you can, when you get stuck ask and do not shy
-
Oct 20th, 2002, 08:15 AM
#4
Monday Morning Lunatic
Depends what's in the list. If you have a list of numbers, then this will work:
Code:
std::list<int> blah;
// add numbers to blah
int x = std::min(blah.begin(), blah.end());
How you decide whether another type of item is smallest is up to you.
What are you storing?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|