Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int insertionSort(int a[],int t){
- for(int j=1;j<t;j++){
- int key = a[j], i = j - 1;
- while(i >= 0 && key < a[i]){
- a[i+1]=a[i];
- i = i-1;
- }
- a[i+1] = key;
- }
- return *a;
- }
- int main() {
- int t;
- cin>>t;
- int a[t];
- for(int i=0;i<t;i++){
- cin>>a[i];
- }
- int sortedArr = insertionSort(a,t);
- for(int i=0;i<t;i++){
- cout<<a[i]<<" ";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment