Bucket sort & list of lists ???

This is a discussion on Bucket sort & list of lists ??? within the C Programming forums, part of the General Programming Boards category; Hello I am having extreme trouble understanding how I can use a list of lists to implement a bucket sort. ...

  1. #1
    EasternStar
    Guest

    Unhappy Bucket sort & list of lists ???

    Hello I am having extreme trouble understanding how I can use a list of lists to implement a bucket sort.

    As is I have already declared a structure which contains a float value and a pointer value.

    I have the user determine how many float values they wish to use and then I call a bucket sort function which according to our assignment is then to call an insert function.

    I have been able to figure out which of the lists of the main list I want to use, but I am clueless as to assign values here? How am I use pointers to create a list within a list?

    I have been searching around and have been unable to cough up any code/ examples of how this works. I would appreciate any help, advance or clarification you provide.

    Sincerely,
    EasternStar

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
    typedef struct node NODE;
    
    NODE {
        NODE *next;
        float data;
    };
    
    NODE *anchorNode;
    NODE *n;
    
    while( ! done )
    {
        promptUserForData( );
        n = myNewNodeAllocation( );
        n->data = readFloatFromUser( );
        addNode( n, anchorNode );
        promptUserToQuit( &done );
    }
    
    [pseudocode]
    addNode( n, a )
    {
        NODE *x;
        for( x = n; x; x = n->next )
            if  x->next && x->data > n->data 
                break;
        if x
            n->next = x->next;
            x->next = n;    
    }
    [/pseudocode]
    That's pretty much all there is to it. The last function is purposefully pseudocode so you can flesh it out yourself. Post your attempt, we'll help ya where you get stuck. Basicly, I wouldn't bother with a sort function. I'd just stick it in the list at the correct location in the first place. But then, that's just me. (Incidently, if it were me, I'd use a double linked list...)

    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  2. Need help sorting a linked list. Beginner
    By scarlet00014 in forum C Programming
    Replies: 1
    Last Post: 09-27-2008, 06:16 PM
  3. Linked list of linked lists???
    By Qui in forum C++ Programming
    Replies: 6
    Last Post: 03-28-2004, 12:13 PM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 09:16 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21