"Mike Wahler" <(EMail Removed)> wrote in message news:<n4Jac.9633$(EMail Removed) link.net>...
> "Mike Jeffers" <(EMail Removed)> wrote in message
> news:(EMail Removed) ...
> > Hi all,
> >
> > I'm pretty new to programming and need help to do a nested sort on a
> > linked list.
> >
> > Basically I'm sorting a list of structures with names, classroom
> > number and floor level. I can sort in scending order any of the 3
> > values but I need to do a nested sort first with floor, followed by
> > classroom number and finally name.
> >
> > Please tell me where I have gone wrong with this.
> > This is my linked list structure:
[snip]
> > Any help will be most appreciated, thanks!
>
> Given objects 'left' and 'right' being compared:
>
> if(left.key1 == right.key1)
> {
> if(left.key2 == right.key2)
> {
> if(left.key3 < right.key3)
> swap(left, right);
> }
> else
> {
> if(left.key2 < right.key2)
> swap(left, right);
> }
> }
> else
> if(left.key1 < right.key1)
> swap(left, right);
> }
>
> Mike
Or, for a shortish list and an easy life, and assuming that your basic
sort algorithm does not rearrange equal elements, just do the sort
three times...
first sort on key3,
then sort on key2,
then sort on key1.
Bill Weston
