Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- int N, max=-1000001, max_idx=0, t=0;
- int A[100001];
- scanf("%d", &N);
- int right_idx=N-1;
- for (int i=0; i<N; i++) scanf("%d", &A[i]);
- while (right_idx>0)
- {
- for (int i=0; i<=right_idx; i++)
- {
- if (A[i]>max)
- {
- max=A[i];
- max_idx=i;
- }
- }
- t=A[right_idx];
- A[right_idx]=max;
- A[max_idx]=t;
- right_idx--;
- max=-1000001;
- max_idx=0;
- }
- for (int i=0; i<N; i++) printf("%d ", A[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement