RE: [Dev-C++] array of strings -- LINKED LIST EXAMPLE
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2003-03-31 07:34:50
|
Reid, I'll enjoy looking through this myself, thanks. Daniel >From: "Reid Thompson" <Rei...@at...> >To: "Khalid El-Kary" ><kha...@ho...>,<Dev...@li...> >Subject: RE: [Dev-C++] array of strings -- LINKED LIST EXAMPLE >Date: Sun, 30 Mar 2003 20:26:00 -0500 > >From >Practical C Programming, 3rd Edition >By Steve Oualline >3rd Edition August 1997 >1-56592-306-5, Order Number: 3065 >451 pages, $34.95 US, $51.95 CA, £24.95 UK > >http://www.oreilly.com/catalog/pcp3/ > >http://examples.oreilly.com/pcp3/ > >I have 1st edition, I highly recommend this book. > > >/******************************************************** > * Define, use and print out an ordered linked list * > * * > * Usage: * > * list * > * * > * Note: Demonstration of an ordered linked list * > ********************************************************/ >#include <stdio.h> >#include <stdlib.h> > >/******************************************************** > * Item for our linked list * > ********************************************************/ >struct item { > int value; /* Value of the item */ > struct item *next_ptr; /* Pointer to the next item */ >}; > >/******************************************************** > * enter -- enter a value in the linked list. * > * * > * Parameters * > * first_ptr -- pointer th the head of the list * > * value -- value to add to the list * > * * > * Restrictions: The first entry must be the lowest. * > * The list must have one item already * > ********************************************************/ >void enter(struct item *first_ptr, const int value) >{ > struct item *before_ptr; /* Item before this one */ > struct item *after_ptr; /* Item after this one */ > struct item *new_item_ptr; /* Item to add */ > > /* Create new item to add to the list */ > > before_ptr = first_ptr; /* Start at the beginning */ > after_ptr = before_ptr->next_ptr; > > while (1) { > if (after_ptr == NULL) > break; > > if (after_ptr->value >= value) > break; > > /* Advance the pointers */ > after_ptr = after_ptr->next_ptr; > before_ptr = before_ptr->next_ptr; > } > > new_item_ptr = malloc(sizeof(struct item)); > new_item_ptr->value = value; /* Set value of item */ > > before_ptr->next_ptr = new_item_ptr; > new_item_ptr->next_ptr = after_ptr; >} >/******************************************************** > * print -- print the linked list * > * * > * Parameter * > * first_ptr -- pointer to the first item on the * > * list * > ********************************************************/ >void print(struct item *first_ptr) >{ > struct item *cur_ptr; /* Pointer to the current item */ > > for (cur_ptr = first_ptr; cur_ptr != NULL; cur_ptr = >cur_ptr->next_ptr) > printf("%d ", cur_ptr->value); > printf("\n"); >} > >int main() >{ > /* The linked list */ > struct item *head_ptr = NULL; > > head_ptr = malloc(sizeof(struct item)); > > head_ptr->value = 0; > head_ptr->next_ptr = NULL; > > enter(head_ptr, 5); > enter(head_ptr, 4); > enter(head_ptr, 8); > enter(head_ptr, 9); > enter(head_ptr, 1); > enter(head_ptr, 2); > > print(head_ptr); > return (0); >} > >-- >thanks, >reid > > >-----Original Message----- >From: Khalid El-Kary [mailto:kha...@ho...] >Sent: Sunday, March 30, 2003 7:31 PM >To: Dev...@li... >Subject: RE: [Dev-C++] array of strings > > >where can i find information about a linked lists, i don't know about them >*shy* > >thanx for the suggestion :-) > >Regards, >Khalid AL-Kary > >why not return them to a linked list rather than an array? > > > >-- > >thanks, > >reid > > >_________________________________________________________________ >Add photos to your e-mail with MSN 8. Get 2 months FREE*. >http://join.msn.com/?page=features/featuredemail > > > >------------------------------------------------------- >This SF.net email is sponsored by: >The Definitive IT and Networking Event. Be There! >NetWorld+Interop Las Vegas 2003 -- Register today! >http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > > >------------------------------------------------------- >This SF.net email is sponsored by: >The Definitive IT and Networking Event. Be There! >NetWorld+Interop Las Vegas 2003 -- Register today! >http://ads.sourceforge.net/cgi-bin/redirect.pl?keyn0001en >_______________________________________________ >Dev-cpp-users mailing list >Dev...@li... >TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm >https://lists.sourceforge.net/lists/listinfo/dev-cpp-users _________________________________________________________________ Express yourself with cool emoticons http://www.msn.co.uk/messenger |