# Bucket sort & list of lists ???

• 11-19-2001
EasternStar
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
• 11-20-2001
quzah
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.