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.