Thread: RE: [Dev-C++] array of strings -- LINKED LIST EXAMPLE
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Reid T. <Rei...@at...> - 2003-03-31 01:26:11
|
From Practical C Programming, 3rd Edition By Steve Oualline 3rd Edition August 1997=20 1-56592-306-5, Order Number: 3065 451 pages, $34.95 US, $51.95 CA, =A324.95 UK http://www.oreilly.com/catalog/pcp3/ http://examples.oreilly.com/pcp3/ I have 1st edition, I highly recommend this book.=20 /******************************************************** * 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 =3D first_ptr; /* Start at the beginning */ after_ptr =3D before_ptr->next_ptr; =20 while (1) { if (after_ptr =3D=3D NULL) break; if (after_ptr->value >=3D value) break; /* Advance the pointers */ after_ptr =3D after_ptr->next_ptr; before_ptr =3D before_ptr->next_ptr; } new_item_ptr =3D malloc(sizeof(struct item)); new_item_ptr->value =3D value; /* Set value of item */ before_ptr->next_ptr =3D new_item_ptr; new_item_ptr->next_ptr =3D 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 =3D first_ptr; cur_ptr !=3D NULL; cur_ptr =3D = cur_ptr->next_ptr) printf("%d ", cur_ptr->value); printf("\n"); } int main() { /* The linked list */ struct item *head_ptr =3D NULL; head_ptr =3D malloc(sizeof(struct item)); head_ptr->value =3D 0; head_ptr->next_ptr =3D 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...]=20 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=20 *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*.=20 http://join.msn.com/?page=3Dfeatures/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 |
|
From: Khalid El-K. <kha...@ho...> - 2003-03-31 02:00:36
|
Thanx Thanx Thanx :-) _________________________________________________________________ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail |
|
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 |
|
From: Louis G. <lg...@ya...> - 2003-03-31 02:04:36
|
Hi
Balazs who is a member of this list
OROSZI_Balázs <or...@vp...>
has great code for what he calls "xlist".
He code applies to both sorted and unsorted linked lists
--- Reid Thompson <Rei...@at...> wrote:
> 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
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
|