Lists are sequence containers that allow non-contiguous memory allocation. As compared to vector, list has slow traversal, but once a position has been found, insertion and deletion are quick. Normally, when we say a List, we talk about doubly linked list. For implementing a singly linked list, we use forward list. ----------------- #include <iostream> #include <list> #include <iterator> using namespace std; //function for printing the elements in a list void showlist(list <int> g) { list <int> :: iterator it; for(it = g.begin(); it != g.end(); ++it) cout << '\t' << *it; cout << '\n'; } int main() { list <int> gqlist1, gqlist2; for (int i = 0; i < 10; ++i) { gqlist1.push_back(i * 2); gqlist2.push_front(i * 3); } cout << "\nList 1 (gqlist1) is : "; showlist(...
Comments
Post a Comment