Talk About Network

Google





Programming > C - C++ Learning > Re: Need help u...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 6 Topic 4059 of 4400
Post > Topic >>

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.
 




 6 Posts in Topic:
Need help using an orderedInsert help for alphabetizing entries.
jawdoc <drbrooks@[EMAI  2008-03-08 15:55:10 
Re: Need help using an orderedInsert help for alphabetizing entr
Ian Collins <ian-news@  2008-03-09 16:53:43 
Re: Need help using an orderedInsert help for alphabetizing entr
Francis Glassborow <fr  2008-03-09 11:25:21 
Re: Need help using an orderedInsert help for alphabetizing entr
"Jim Langston"   2008-03-09 12:33:34 
Re: Need help using an orderedInsert help for alphabetizing entr
Francis Glassborow <fr  2008-03-11 14:01:46 
Re: Need help using an orderedInsert help for alphabetizing entr
"Daniel T." <  2008-03-09 16:07:00 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 11:43:59 PST 2009.