Results 1 to 4 of 4

Thread: Smallest iteam using Link list

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    10

    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

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    10
    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

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width