Closed SONIYAPATIDAR closed 1 year ago
using namespace std; void insertionSort(vector&arr){ for(int i=1;i<arr.size(); i++){ int key=arr[i]; int j=i-1; while(j>=0&&arr[j]>key){ arr[j+1]=arr[j]; j--; arr[j+1]=key; }
} for(int ele:arr){ cout<<ele<<" ";
} cout<<"\n";
}
int main(){ vectorarr={1,4,6,8,5,9}; insertionSort(arr);
Please add the filename inside a folder from the coding platform it belongs. Also add problem code in filename. For details please check guidelines in readme.
include
include
using namespace std; void insertionSort(vector&arr){
for(int i=1;i<arr.size(); i++){
int key=arr[i];
int j=i-1;
while(j>=0&&arr[j]>key){
arr[j+1]=arr[j];
j--;
arr[j+1]=key;
}
} for(int ele:arr){ cout<<ele<<" ";
}
int main(){ vectorarr={1,4,6,8,5,9};
insertionSort(arr);
}