Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 100
- int n, a[NMAX];
- void citire(int& n, int a[])
- {
- cin >> n;
- for (int i = 0; i < n; i++)
- cin >> a[i];
- }
- int cmp(int a, int b, char cmpOp)
- {
- if (cmpOp == '<')
- return a <= b;
- return a >= b;
- }
- void sortare(int a[], int p1, int p2, char cmpOp)
- {
- int sortat = 0;
- while (!sortat)
- {
- sortat = 1;
- for (int i = p1; i < p2; i++)
- if (!cmp(a[i], a[i + 1], cmpOp))
- {
- swap(a[i], a[i + 1]);
- sortat = 0;
- }
- }
- }
- void scrie(int n, int a[])
- {
- for (int i = 0; i < n; i++)
- cout << a[i] << ' ';
- }
- int main()
- {
- citire(n, a);
- sortare(a, 0, n / 2 - 1, '<');
- sortare(a, n / 2, n - 1, '>');
- scrie(n, a);
- return 0;
- }
Add Comment
Please, Sign In to add comment