Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int v[100],n,i,j,x,nr=0,m,l;
- cout<<"n= ";cin>>n;
- for (i=1;i<=n;i++)
- {cin>>x;
- if (nr==0 || x < v[nr])
- {
- nr++;
- v[nr]=x;
- }
- else
- { // sar elementele mai mari ca x
- j=1;
- while (v[j]>x)
- j++;
- if (v[j]<x)
- {
- // mutam toate elem. spre dreapta cu o pozitie
- for (l=m;l>=j;l--)
- v[l+1]=v[l];
- nr++;
- v[j]=x;
- }
- }
- }
- for (i=1;i<=n;i++)
- cout<<v[i]<<" ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement