Linked lists, queues, and stacks

I am learning the title, linked lists, queues FIFO, and stacks LIFO. I've been looking through the code resources on the site and I can't really find a clear description of how to define one in code. Do you create these like you would a class? How customizable are they? Also, do they have member functions that you put in place, or does C++ template these, for instance like a vector or array (having their own methods)? With that said, what can be stored in them, and how do you access or use them in code? Like if I wanted to store a list of objects, can you access that objects member functions directly from the list?

EDIT:

One more question I forgot, sorry! Can each of these types size be limited? Like if you have a queue, and you push numbers in, is there a way that you can make a maximum queue size? So that once you get 5 variables, and you push another in at the end, the one in the "head" gets delete? Or is this is just done by standard code implementation such as if else statements?
Last edited on
I've been looking through the code resources on the site and I can't really find a clear description of how to define one in code.
Odd. It seems to me that these things are explained quite well in here ( http://www.cplusplus.com/reference/stl/ )
Note that queues and stacks are only wrappers for other containers (deque, unless you specify differently)
Generally, lists and deques look do stuff the same way vector does (from the users point of view)
For example to create a list object write list<any_struct_or_class_here> my_list;, to add something to that list writemy_list.push_back(any_object_of_the_class_you_specified_when_you_declared_the_list);
Accessing elements in a list is a little more complicated, because you can't use [] operator. Usually you'll have to iterate through the whole list. see http://www.cplusplus.com/reference/stl/list/begin/
You can access anything an element has. You usually do that either with methods list::front() and list::back() or an iterator.
Can each of these types size be limited?
You'll have to do this yourself, I believe. It's not hard though...
Good luck
Topic archived. No new replies allowed.