Skip to main content

Swap in C++

 


#include<bits/stdc++.h>

using namespace std;

int main()
{
    // Swap element vector
   
    // vector<int> v = {1,2,3,4};
    // vector<int> v1 = {5,6,7,8};
    // swap(v,v1);
    // for(auto element:v){
    //     cout<<element<<" ";

    // }
    // cout<<endl;
    // for(auto element:v1){
    //     cout<<element<<" ";
    // }


    // Swap element in Array
    int a[]= {1,2};
    int b[]= {3,6};
    swap(a,b);
     for(auto element:a){
        cout<<element<<" ";
    }
    cout<<endl;
    for(auto element:b){
        cout<<element<<" ";
    }

    return 0;
}


Comments