Advertisement
rotti321

Inserarea unui elem x intr-un sir sort

Mar 21st, 2022
661
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     ifstream cin("test.in");
  7. //  ofstream cout("test.out");
  8.  
  9.     int n,a[1001],x,i,j;
  10.     cin>>n;
  11.     for(i=1;i<=n;i++){ ///a- sir ord cresc
  12.         cin>>a[i];
  13.     }
  14.     cin>>x;
  15.     j=n;
  16.     while(j>0 && x<a[j]){
  17.         a[j+1]=a[j];
  18.         j--;
  19.     }
  20.     j++;
  21.     a[j]=x;
  22.     n++;
  23.     for(int i=1;i<=n;i++){
  24.         cout<<a[i]<< " ";
  25.     }
  26.  
  27. }
  28.  
Advertisement
RAW Paste Data Copied
Advertisement