Thread: Bucket sort & list of lists ???

  1. #1

    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.


  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    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 );
    addNode( n, a )
        NODE *x;
        for( x = n; x; x = n->next )
            if  x->next && x->data > n->data 
        if x
            n->next = x->next;
            x->next = n;    
    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...)

    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, 01:13 PM
  4. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM