Guest User

Untitled

a guest
Jan 20th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int insertionSort(int a[],int t){
  5. for(int j=1;j<t;j++){
  6. int key = a[j], i = j - 1;
  7.  
  8. while(i >= 0 && key < a[i]){
  9. a[i+1]=a[i];
  10. i = i-1;
  11. }
  12. a[i+1] = key;
  13. }
  14. return *a;
  15. }
  16.  
  17. int main() {
  18. int t;
  19. cin>>t;
  20. int a[t];
  21. for(int i=0;i<t;i++){
  22. cin>>a[i];
  23. }
  24.  
  25. int sortedArr = insertionSort(a,t);
  26.  
  27. for(int i=0;i<t;i++){
  28. cout<<a[i]<<" ";
  29. }
  30.  
  31. return 0;
  32. }
Add Comment
Please, Sign In to add comment