Author |
Message |
io #1 / 16
|
liked lists in c
Hi do you know where can i find an example of linked lists in C.
|
Mon, 10 Mar 2003 03:00:00 GMT |
|
|
WebBu #2 / 16
|
liked lists in c
Quote:
> Hi do you know where can i find an example of linked lists in C.
"C the complete reference, third edition" by herbert schildt, McGraw Hill Osborne isbn: 0-07-882101-0 pages 553-580 --
Comp-unix-programmer: FAQ URL: http://www.erlenstar.demon.co.uk/unix/faq_toc.html URL: http://www.whitefang.com/unix/faq_toc.html comp.lang.c FAQ: <http://www.eskimo.com/~scs/C-faq/top.html>.
|
Mon, 10 Mar 2003 03:00:00 GMT |
|
|
Richard Heathfiel #3 / 16
|
liked lists in c
Quote:
> > Hi do you know where can i find an example of linked lists in C. > "C the complete reference, third edition" by herbert schildt, McGraw > Hill Osborne > isbn: 0-07-882101-0 > pages 553-580
This may, or may not, be wise advice. It is likely that Schildt knows what a linked list is, and it's even likely that he explains it well. What is somewhat less likely is that his implementation is robust. If you must use Schildt as a tutorial source, treat his books like "Numerical Recipes" - in other words, read the text if you like, but treat his C code with the utmost care. -- Richard Heathfield "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999. C FAQ: http://www.eskimo.com/~scs/C-faq/top.html 65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32 to go)
|
Mon, 10 Mar 2003 03:00:00 GMT |
|
|
WebBu #4 / 16
|
liked lists in c
Quote:
> > > Hi do you know where can i find an example of linked lists in C. > > "C the complete reference, third edition" by herbert schildt, McGraw > > Hill Osborne > > isbn: 0-07-882101-0 > > pages 553-580 > This may, or may not, be wise advice. It is likely that Schildt knows > what a linked list is, and it's even likely that he explains it well. > What is somewhat less likely is that his implementation is robust.
I guess I should add that I find this book to have very good explanations of C, with examples that are illustrative, but not actually usable. I feel that this book offers excellent explanations on an introductory level, sort of get the basics down pat in a simple and straight forward manner. Would you suggest another book that would be an excellent introduction to ANSI C? that articulates the differences between the two ANSI's? And that covers ANSI rather exhaustively? --
Comp-unix-programmer: FAQ URL: http://www.erlenstar.demon.co.uk/unix/faq_toc.html URL: http://www.whitefang.com/unix/faq_toc.html comp.lang.c FAQ: <http://www.eskimo.com/~scs/C-faq/top.html>.
|
Tue, 11 Mar 2003 03:00:00 GMT |
|
|
nic #5 / 16
|
liked lists in c
Quote:
>> > > Hi do you know where can i find an example of linked >> > > lists in C. >> > "C the complete reference, third edition" by herbert >> > schildt, McGraw Hill Osborne >> > isbn: 0-07-882101-0 >> > pages 553-580 >> This may, or may not, be wise advice. It is likely that >> Schildt knows what a linked list is, and it's even likely >> that he explains it well. What is somewhat less likely is >> that his implementation is robust. >I guess I should add that I find this book to have very good >explanations of C, with examples that are illustrative, but >not actually usable. I feel that this book offers excellent >explanations on an introductory level, sort of get the basics >down pat in a simple and straight forward manner.
As you already have this book, it would be too late to suggest not getting it, but I would recommend having a look at this site: http://www.plethora.net/~seebs/c/c_tcr.html -- regards, nick
|
Tue, 11 Mar 2003 03:00:00 GMT |
|
|
Richard Heathfiel #6 / 16
|
liked lists in c
Quote:
> > > > Hi do you know where can i find an example of linked lists in C. > > > "C the complete reference, third edition" by herbert schildt, McGraw > > > Hill Osborne > > > isbn: 0-07-882101-0 > > > pages 553-580 > > This may, or may not, be wise advice. It is likely that Schildt knows > > what a linked list is, and it's even likely that he explains it well. > > What is somewhat less likely is that his implementation is robust. > I guess I should add that I find this book to have very good explanations > of C, with examples that are illustrative, but not actually usable. I > feel that this book offers excellent explanations on an introductory > level, sort of get the basics down pat in a simple and straight forward > manner.
As another respondent indicates, the book is littered with errors, just a small sample of which have been documented by Seebs. Quote: > Would you suggest another book that would be an excellent introduction to > ANSI C? that articulates the differences between the two ANSI's? And that > covers ANSI rather exhaustively?
The usual recommendations from comp.lang.c are: GENERAL INTRODUCTION/TUTORIAL: 1) For real beginners looking for a solid introduction: C Programming: A Modern Approach. K.N.King. W.W.Norton & Company, 1996. ISBN 0-393-96945-2 2) For somewhat more experienced users looking for a solid introduction: The C Programming Language, 2nd Ed. Kernigan & Ritchie. Prentice Hall, 1988. ISBN 0-13-110362-8 3) Other recommended introductory books: C: How to Program, 2nd Ed. Deitel, H.M. & Deitel, P.J. Prentice Hall, 1994. ISBN: 0-13-226119-7 REFERENCES: C : A Reference Manual, 4th Ed. Harbison & Steele. Prentice Hall, 1995. ISBN 0-13-326224-3 The Standard C Library. P.J.Plauger. Prentice Hall, 1992. ISBN 0-13-131509-9 C Programming FAQs Steve Summit Addison-Wesley, 1996. ISBN 0-201-84519-9 ADVANCED TOPICS / FURTHER EXPLORATION: C Traps and Pitfalls. Andrew Koenig. Addison-Wesley, 1989. ISBN 0-201-17928-8 Expert C Programming: Deep C Secrets, Peter Van Der Linden, Prentice Hall, 1994. ISBN 0-13-177429-8 Practical C Programming. Steve Oualline. O'Reilly & Associates, 1993. ISBN 1-56592-035-X Problem Solving And Program Design In C, 2nd Ed. Hanly & Koffman. Addison-Wesley, 1996. ISBN 0-201-59063-8 Algorithms in C, 3rd Ed. Robert Sedgewick Addison-Wesley, 1998. ISBN 0-201-31452-5 As for differences between the "two ANSIs", I presume you mean C89 and C99. (Let me word this very carefully...) The only book I have *read* that covers the changes is "C Unleashed", by Heathfield, Kirby et al. (al knows who he is!)... I didn't write the C99 chapter, you'll be glad to hear. That was done by Peter Seebach, a member of the ANSI C committee. I am not in a position to advocate this book, however, because this is a technical newsgroup, not a commercial forum. You will have to either solicit opinions from people who've read it, or browse it in a bookshop, and make up your own mind. What I /can/ say, however, is that the book also covers linked lists (the subject of this thread) - but then, I suspect that most of the books in the above list also do this. -- Richard Heathfield "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999. C FAQ: http://www.eskimo.com/~scs/C-faq/top.html 65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32 to go)
|
Tue, 11 Mar 2003 03:00:00 GMT |
|
|
Chris Ke #7 / 16
|
liked lists in c
following: Quote: >I guess I should add that I find this book to have very good explanations >of C, with examples that are illustrative, but not actually usable. I >feel that this book offers excellent explanations on an introductory >level, sort of get the basics down pat in a simple and straight forward >manner.
Unfortunately, some of his explanations are wrong. Schildt does not appear to know the difference between an ANSI C feature and one which is implementation defined (or undefined). The explanations may be easy to understand, but correctness does not have to be sacrificed in favor of ease of comprehension. Quote: >Would you suggest another book that would be an excellent introduction to >ANSI C? that articulates the differences between the two ANSI's? And that >covers ANSI rather exhaustively?
K&R covers ANSI sufficiently and correctly. So does Harbison & Steele. -Chris -- http://www.math.grinnell.edu/~kern/index.html
|
Tue, 11 Mar 2003 03:00:00 GMT |
|
|
Ben Pfaf #8 / 16
|
liked lists in c
Quote:
> On Fri, 22 Sep 2000 23:05:15 +0100, Richard Heathfield
> >As for differences between the "two ANSIs", I presume you mean C89 and > >C99. (Let me word this very carefully...) The only book I have *read* > >that covers the changes is "C Unleashed", by Heathfield, Kirby et al. > >(al knows who he is!)... > This is rather off-topic, but is it just coincidence that many of the > listed authors (and editors :-) for that book are c.l.c posters? Or > did that book somehow arise from the newsgroup?
It is not a coincidence. Richard approached many of us as possible authors for the book because he knew us from c.l.c. -- "What is appropriate for the master is not appropriate for the novice. You must understand the Tao before transcending structure." --The Tao of Programming
|
Tue, 11 Mar 2003 03:00:00 GMT |
|
|
Chris Ke #9 / 16
|
liked lists in c
On Fri, 22 Sep 2000 23:05:15 +0100, Richard Heathfield
Quote: >As for differences between the "two ANSIs", I presume you mean C89 and >C99. (Let me word this very carefully...) The only book I have *read* >that covers the changes is "C Unleashed", by Heathfield, Kirby et al. >(al knows who he is!)...
This is rather off-topic, but is it just coincidence that many of the listed authors (and editors :-) for that book are c.l.c posters? Or did that book somehow arise from the newsgroup? -Chris -- http://www.math.grinnell.edu/~kern/index.html
|
Wed, 12 Mar 2003 08:21:19 GMT |
|
|
Chris Mear #10 / 16
|
liked lists in c
Quote:
>> On Fri, 22 Sep 2000 23:05:15 +0100, Richard Heathfield
>> >As for differences between the "two ANSIs", I presume you mean C89 and >> >C99. (Let me word this very carefully...) The only book I have *read* >> >that covers the changes is "C Unleashed", by Heathfield, Kirby et al. >> >(al knows who he is!)... >> This is rather off-topic, but is it just coincidence that many of the >> listed authors (and editors :-) for that book are c.l.c posters? Or >> did that book somehow arise from the newsgroup? >Imagine Richard Heathfield in some evil frenzy, wrenching the noses of many >CLC regulars in some wicked plot to create the world's greatest tree killer. >Another copy got printed? There goes another acre of Amazon rainforest. >The deep and abiding shame that must be at the core of it all. It makes me >shudder.
The damage to nature would be greatly reduced if there weren't so many {*filter*}y pictures in chapter 13.
|
Wed, 12 Mar 2003 14:05:52 GMT |
|
|
JT #11 / 16
|
liked lists in c
Quote: > Hi do you know where can i find an example of linked lists in C.
Just define a struct, that contains all the valuefields and add one more field that has a pointer to this same struct type. This pointer points to the next node in the list, the last node's next-pointer is simply assigned to NULL. Example: struct Node__{ int value; struct Node__ *next; Quote: }Node;
You must have a pointer to the first node (NULL if an empty list) of the list. When adding a node, you must dynamically allocate (use malloc ()) memory for the new node. Then if this is the first node in the list, make the list-pointer point to this node. Otherwise you either make the last node's next pointer point to this new node (and make the new node's next point to NULL) or make the new node's next point to the previously first node in the list and make the list pointer point to this new node. Examples: Add to the end of the list: for (i = pList; i != NULL; i = i->next); /* Find the last node */ i->next = pnew; /* Make the last node point to the new node */ pNew->next = NULL; /* Make the new node.next point to NULL */ Add to the beginning of the list: pNew->next = pList; /* Make the new point to the previously first node */ pList = pNew; /* Make the list-pointer point to the new node */ To make the list double linked, add a pointer to the previous node. To make a stack, only allow adding to the beginning of the list and removing from the beginning only also. To make a qeue, only allow adding to the beginning and removing from the end. A good book for additional information is Data Structures And Algorithm Analysis in C (by Weiss). -JT Sent via Deja.com http://www.deja.com/ Before you buy.
|
Wed, 12 Mar 2003 03:00:00 GMT |
|
|
Richard Heathfiel #12 / 16
|
liked lists in c
Quote:
> On Fri, 22 Sep 2000 23:05:15 +0100, Richard Heathfield
> >As for differences between the "two ANSIs", I presume you mean C89 and > >C99. (Let me word this very carefully...) The only book I have *read* > >that covers the changes is "C Unleashed", by Heathfield, Kirby et al. > >(al knows who he is!)... > This is rather off-topic, but is it just coincidence that many of the > listed authors (and editors :-) for that book are c.l.c posters? Or > did that book somehow arise from the newsgroup?
I don't know where the "editors" thing comes from. Peter Seebach was one of the technical editors, but Amazon's description of Lawrence and myself as "editors" is weird - I don't recall doing any editing, at least not of other people's stuff. Very brief and wildly inaccurate historical/hysterical note on sequence of events as I remember them: (a) Publisher asked me to review Table of Contents outline for proposed book on C. I don't know why they chose me in particular, but they were certainly trawling newsgroups (read-only, I hasten to add). (b) I did the review. Er, "I didn't entirely approve of the outline" is probably the kindest thing I can say. (c) The author read my review and promptly gave up on the whole idea, leaving the publisher without an author. (d) Nothing happened for a long time :-) except for a flurry of emails with publisher dropping what appeared to be broader and broader hints. (e) Eventually I cottoned on and offered to write a ToC myself. (f) Not realising that there were other people submitting ToCs as well, and having been told I wasn't expected to write more than a small handful of chapters, I started dishing out invitations to the gurus here to write individual chapters. (This is probably why it has a certain "collection of conference papers" feel to it, as one reviewer put it, rather than a homogenous book - there simply wasn't /time/ to collaborate as much as we probably would have liked.) The most charming "no" I got was, of course, from Chris Torek. (He said "no" again a few months later, even /more/ charmingly. I've come to the conclusion that the more charming Chris is, the more carefully you have to watch him!) IIRC Kaz never got an invite - big mistake on my part. And Dan Pop wasn't around at the time. Steve Summit said "no" (which, much later, changed to a "yes", presumably because more time had become available to him). I never heard back from Tom Torfs - I think he's busy writing a C99 compiler. :-) One comp.lang.c regular said "yes" but eventually that became a "no" for reasons I don't fully understand; I think he fell out with the publisher actually, but that's another story. (g) Fortunately, the ToC /was/ accepted, otherwise I'd never have lived it down in comp.lang.c! Lawrence came in as co-author the same weekend the ToC was approved, IIRC. (h) The people I didn't invite personally are: Sam Hobbs, Scott Fluhrer, William Fishburne. Lawrence may have been responsible for one or two of these. They all did excellent stuff, though, so whoever chose them, chose well. (i) The people you might not recognise by name: Mathew Watson (has posted in comp.lang.c once, IIRC), Ian Kelly (a lurker) - both are former colleagues of mine; Mike Wright, Chad Dixon, Ian Woods (although Ian seems to have discovered clc at last) - are Netizens I got to know in the last couple of years via various nefarious means. I hope this answers your question, anyway. [re-checks through post looking for commercial content] [finds none] [clicks "Send"] -- Richard Heathfield "Usenet is a strange place." - Dennis M Ritchie, 29 July 1999. C FAQ: http://www.eskimo.com/~scs/C-faq/top.html 65 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (32 to go)
|
Wed, 12 Mar 2003 03:00:00 GMT |
|
|
JT #13 / 16
|
liked lists in c
Correction... I made an error in the first example. Here's the correct one: Add to the end of the list: for (i = pList; i->next != NULL; i = i->next); /* Find the last node */ i->next = pnew; /* Make the last node point to the new node */ pNew->next = NULL; /* Make the new node.next point to NULL */ The error was in the for-loop. The first version would have missed the last element and given you a NULL i. -JT Sent via Deja.com http://www.deja.com/ Before you buy.
|
Wed, 12 Mar 2003 03:00:00 GMT |
|
|
John D. Sto #14 / 16
|
liked lists in c
Quote:
> To make a queue, only allow adding to the beginning and > removing from the end.
And you'd probably want to have a variable to keep track of the last element, so that you don't have to look through the entire list each time you want to draw from the end -- jonh stout gt5206b
|
Wed, 12 Mar 2003 03:00:00 GMT |
|
|
Page 1 of 2
|
[ 16 post ] |
|
Go to page:
[1]
[2] |
|