Archived

This topic is now archived and is closed to further replies.

Star2

I dont understand Linked Lists

Recommended Posts

So, from what I get, Linked Lists are something you create yourself ?? Its not a built-in "function" in C++ right? Cuz as of what I saw in a code that sorted numbers, it was all coded customly. You cant define a linked list like a function/class right? Thanks for your help.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
A linked list isn''t really a function or anything like that. The idea of a "linked list" isn''t something that is defined like an int. It''s a conceptual thing that you''re free to implement however you want. Basically the idea is that you have a class which holds some data. Part of the data that that class holds is a pointer to the next instance of the class. In this way, you have a list of instances of classes "linked together." Their might be some linked lists defined in the libraries that come with your compiler, if not, it isn''t too terribly difficult to write one yourself. If you''d like some instruction on how to do that, you could probably find a lot of tutorials or something on the web. If you have no luck there, I could send you some info. Good luck.

Share this post


Link to post
Share on other sites
Thanks for the help,

I know how to make them, but I was just confused over that I had to write it myself and still it had a name, but I get it now, its just a concept.

Now I understand.

Share this post


Link to post
Share on other sites
There are classes you can use to make it quicker, those are bundled and called STL. Standard Template Library, that is. So thesse are pretty standard C++. But people like me, ust make there own linked lists. The choice is all yours!

.lick

Share this post


Link to post
Share on other sites
quote:
Original post by Anonymous Poster
Their might be some linked lists defined in the libraries that come with your compiler, if not, it isn''t too terribly difficult to write one yourself.

If you are using C++, there is no "might" about it. All conforming C++ compilers must ship with an implementation of std::list.



"The fact that a believer is happier than a skeptic is no more to the point than the fact that a drunken man is happier than a sober one." -- George Bernhard Shaw

Share this post


Link to post
Share on other sites
quote:
Original post by Pipo DeClown
But people like me, ust make there own linked lists.

What kind of people might that be?



"The fact that a believer is happier than a skeptic is no more to the point than the fact that a drunken man is happier than a sober one." -- George Bernhard Shaw

Share this post


Link to post
Share on other sites
Think of a linked list as an array which holds pointers to objects in memory. The difference between an array declared like this:

CMyObect* SomeObject[12]; //12 pointers to CMyObject''s

and a linked list is this: You can add and change the number of objects in a linked list, but the array is definitly going to be (in this example) 12 objects, unless you delete it and reassign it. the linked list can have 0 entries or 100, it doesn''t matter. You don''t need to delete the linked list to change the number of entries; It can change size dynamically.

A linked list is a data structure. If you don''t understand what a linked list is or how to implement it, then you won''t understand BSP trees or Octrees. These are data structures as well, but they form a basis on linked lists. I wouldn''t use the STL until you fully understand how to create a linked list yourself.

Share this post


Link to post
Share on other sites