Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Latest commit

 

History

History
30 lines (23 loc) · 759 Bytes

swap.md

File metadata and controls

30 lines (23 loc) · 759 Bytes

swap

Description : This function is used to swap the contents of one list with another list of same type and size.

Example:

    // list container declaration 
    std::list<int> mylist1{ 1, 2, 3, 4 }; 
    std::list<int> mylist2{ 3, 5, 7, 9 }; 
  
    // using swap() function to  
    //swap elements of lists 
    mylist1.swap(mylist2); 
  
    // printing the first list 
    std::cout << "mylist1 = "; 
    for (auto value : mylist1) {
        std::cout << ' ' << value; 
    }
  
    // printing the second list 
    std::cout << std::endl << "mylist2 = "; 
    for (auto value : mylist2) {
        std::cout << ' ' << value; 
    }

See Sample Code Run Code