Reverse Array In optimal time
Hello Everyone Hopes all will be fine Welcome to my another blog. In this blog We are learning that how to reverse an array in optimal time. CODE IS HERE... #include <iostream> #include<vector> using namespace std; vector<int> reverse( vector <int> v ){ int s =0; int e =v.size()-1; while(s<=e){ swap(v[s], v[e]); s++; e--; } return v; } void print(vector<int> v){ for(int i=0;i<v.size();i++){ cout<<v[i]<<" "; } cout<<endl; } int main() { vector<int> v; v.push_back(41); v.push_back(7); v.push_back(23); v.push_back(3); v.push_back(4); vector<int> ans = reverse(v); print(ans); } KEEP PRACTICING || HAPPY CODING ........