Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void sortArraySelection(float a[], int n, int m)
- {
- int i, j, minIndex, tmp;
- for(i=0; i < n-1; i++)
- {
- minIndex = i;
- for(int j = i+1; j < n; j++)
- {
- if(m == 1)
- {
- if(a[j] < a[minIndex])
- {
- minIndex = j;
- }
- }
- else if(m == 0)
- {
- if(a[j] > a[minIndex])
- {
- minIndex = j;
- }
- }
- }
- if(minIndex != i)
- {
- tmp = a[i];
- a[i] = a[minIndex];
- a[minIndex] = tmp;
- }
- }
- }
- main()
- {
- float a[100005];
- int n, m;
- cin>>n>>m;
- for(int i=0; i<n; i++) cin>>a[i];
- sortArraySelection(a, n, m);
- for(int i=0; i<n; i++)
- {
- cout<<a[i]<<' ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement