#include<bits/stdc++.h> using namespace std; int sum=0; vector<int> rev(vector<int>& nums,int f,int r) { if(f<=r) { swap(nums[f],nums[r]); rev(nums,f+1,r-1); } return nums; } int main() { vector<int> v = {4,5,2,6,3,56,5}; rev(v,0,6); for(int i=0;i<=6;++i) cout<<v[i]<<" "; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter