Lists are sequence containers that allow non-contiguous memory allocation.The include the header file to #include < list > . A list is a number of items in an ordered or unordered structure. A list can be used for a number of things like storing items or deleting and adding items
The program demonstrates the use of the STL List container in C++.
#include<iostream> #include<list> using namespace std; //STL-List in C++ void print(list<int> x){ for(int o : x){ cout<<" "<<o; } cout<<endl; } int main() { list <int> a={70,20,50,10}; print(a); list<int> b; b.push_front(150); b.push_front(250); b.push_back(350); print(b); cout<<"List First Element in A : "<<a.front()<<endl; cout<<"List Last Element in A : "<<a.back()<<endl; cout<<"Empty or Not : "<<a.empty()<<endl; cout<<"Before Reverse : "; print(a); a.reverse(); cout<<"After Reverse : "; print(a); cout<<"Before Sort : "; print(a); a.sort(); cout<<"After Sort : "; print(a); return 0; }
70 20 50 10 250 150 350 List First Element in A : 70 List Last Element in A : 10 Empty or Not : 0 Before Reverse : 70 20 50 10 After Reverse : 10 50 20 70 Before Sort : 10 50 20 70 After Sort : 10 20 50 70To download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions