Re: Need help using an orderedInsert help for alphabetizing entries.
by "Daniel T." <daniel_t@[EMAIL PROTECTED]
>
Mar 9, 2008 at 04:07 PM
On Mar 8, 7:55=A0pm, jawdoc <drbro...@[EMAIL PROTECTED]
> wrote:
> I am working on alphabetizing entries in my linked list and am very
> confused on how to do this. What I'm trying to do is to go through the
> list and order them accordingly. The struct consists of last name,
> first name, and some other stuff. I will provide the full code that is
> working but will only add to the top of the list but won't alphabetize
> it.
First you need a linked list class. You have the node (the SEAT class)
but you don't have the list class itself.
class SeatList {
SeatList( const SeatList& );
SeatList& operator=3D( const SeatList& );
SEAT* first;
public:
SeatList(): first( 0 ) { }
~SeatList() {
while ( first ) {
SEAT* tmp =3D first;
first =3D tmp->next;
delete tmp;
}
}
void addSeat( SEAT* seat ) {
if ( first =3D=3D 0 ) {
first =3D seat;
first->next =3D 0;
}
else {
// here you have to iterate through the seats that have been
save
// so far until you find the spot you want to insert this
seat
}
}
SEAT* getFirst() { return first; }
};
The above should get you started. Just put a SeatList in your main
instead of your 'head' object.