Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int main()
- {
- ifstream fin("halfsort2.in");
- ofstream fout("halfsort2.out");
- int n;
- fin>>n;
- int vec[n + 1];
- for (int i = 1; i <= n; i++)
- fin>>vec[i];
- int aux;
- for (int i = 1; i < n - 1; i += 2)
- for (int j = i + 2; j < n; j += 2)
- if (vec[i] < vec[j])
- {
- aux = vec[i];
- vec[i] = vec[j];
- vec[j] = aux;
- }
- for (int i = 2; i < n; i += 2)
- for (int j = i + 2; j <= n; j += 2)
- if (vec[i] > vec[j])
- {
- aux = vec[i];
- vec[i] = vec[j];
- vec[j] = aux;
- }
- for (int i = 1; i <= n; i++)
- fout<<vec[i]<<' ';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement