Răspuns :
Răspuns:
#include <iostream>
#include <fstream>
//declarare fuctii citire afisare
std::ifstream citeste("bilet22.txt");//in loc de std::cin
std::ofstream afiseaza("bilet22.txt"); //in loc de std::cout
int main()
{
#define p_size 21
int p[p_size];//marime maxima
unsigned int define_size;
std::cout << "introdu marimea vectorului(<=21): "; std::cin >> define_size; //citeste si memoreaza marimea vectorului
for (unsigned int i = 0; i <define_size; i++)
{
std::cout << "elementul: "<<i<< " = "; std::cin >> p[i];//introducere elemente in ordine descrescatoare
}
for (unsigned int index = 0; index < define_size-1; index++)
{
if (index % 2 == 0) //pozitie para
{
//cauta sortarea Bubble
unsigned int temp;
for (unsigned int j = 0; j < define_size-index-1; j++)
{
if (p[j] > p[j + 1])
{
temp = p[j];
p[j] = p[j + 1];
p[j + 1] = temp;
}
}
}
else continue; //impar
}
std::cout << "Afisare vector: ";
for (size_t i = 0; i < define_size; i++)
{
std::cout << p[i]<<" ";
}
//made by N0nNaMe
}
Explicație: