   Questions about lists
  Are linked_lists obsolete now?Should I be using lists instead?If so, are lists basically the same as linked_lists, or are they different?Can you use lists with classes and structs?How do you access the elements of the list, or add more elements to it?If you can use lists with classes, do you just access the element in the list and use . to modify the members?Sorry for the bunch of questions, but I'm having some trouble... I'm not very good with the STL, mostly because I prefer to make classes myself rather than rely on other people.[Edited by - EmrldDrgn on July 26, 2006 2:30:32 AM]
  Yes, linked lists are obsolete. However studying them is good practise, i.m.h.o. It depends on your programming language: in my case, Delphi, all is taken care of in a class Tlist.What language are you using?   ;  Shoot... I always forget to say that... I should put that in a sig...I'm using C++, compiling with VC++ '05 Express, and developing on and for Windows.   ;std::list provides the same functionality and complexity guarantees that one would expect from a list. You can use std::list to store any object with a copy constructor and an assignment operator. You access the elements of the list using its iterators. The first element in the list l corresponds to the iterator l.begin(). The second element corresponds to the iterator l.begin() + 1, and so on until l.end() which is a past-the-end iterator (right after the last element). You can add elements to the list using l.insert, l.push_back or l.push_front, and remove them with l.erase, l.remove, l.pop_front and l.pop_back. Of course, you can also use a front_inserter or back_inserter and std::copy or std::transform.;  What about arrays of lists? Can I use list_array[0][0].begin(); to access the first element in the first list in my array? I've been trying it and it doesn't seem to be working...   ;  The first element in the first list in your array:list_arrayYour arraylist_array[0]The first list in your arraylist_array[0].begin()The first iterator in the first list in your array*(list_array[0].begin())The first element in the firs list in your array.Alternative:list_array[0].front()   ;Quote:Original post by MarminYes, linked lists are obsolete. However studying them is good practise, i.m.h.o.Linked lists are important building blocks for other data structures.The very fast splice operation lists provide is essential for several high-performance datastructures and they are used in many lock-free concurrent datastructures.   ;  I'm still having some problems, so I'll share some code.I declare my array of lists of map_tiles like this:list<map_tiles> map[MAP_SIZEY][MAP_SIZEX];where MAP_SIZEY and MAP_SIZEX are #defined to 10.Then I try to access the first element in the list like this:*(map[0][0].begin());and I get the error: Cannot allocate an array of constant size 0.It's telling me that I haven't already created the array map, but I clearly have.This is strange to me. Any suggestions?   ;  Are you sure your #defines are correct (side question: why are you using defines instead of integer constants?), and if they are then post more code.   ;  I'm using #defines instead of integer constants because I need to know the map size elsewhere, and this way: A., I just have to change the #define statement to alter all instances of MAP_SIZE, and B., I know what I'm referring to. 10 could be anything with a value of 10, but MAP_SIZE tells me it's the map dimensions. Is this a bad thing?Anyway, I solved my problem. It was something incredibly stupid, as I suspected. I typed "ma" instead of "map" when I declared the array, and I was trying to initialize the members of the lists outside of any functions, which, needless to say, was wrong.   