Lists are good when data needs to be reorganized a lot. To
be able to use STL
lists add this before you start using them in your source code:
#include <list>
Suppose
that T is any type or class - say an int, a float, a struct, or a class, then
list<T> l;
declares a new and empty list called l. Given an object l:
test to see if l is empty:
l.empty()
find how many items are in l:
l.size()
push a t:T onto the end of l:
l.push_back(t)
pop the last off l:
l.pop_back()
push a t:T onto the start of l:
l.push_front(t)
pop the front of l off l:
l.pop_front()
get the front item of l:
l.front()
- change the front item:
l.front() = expression.
get the back item of l:
l.back()
- change the back item:
l.back() = expression.
- Sort the list:
l.sort()
- Clear the list:
l.clear()
- Merge in a sorted list into a sorted list:
l.merge(list_of_sorted_elements)
- Reverse the list:
l.reverse()
Assign a copy of q1 to q:
q = q1
No comments:
Post a Comment