void Init(int * iAr, int Size); void Show(int * iAr, int Size); void Sort(int *iAr, int Size); int main() { int iSize = 10; int *iAr= new int [iSize]; cout<<"Massiv do sort"<<endl; Init(iAr, iSize); Show(iAr, iSize); Sort(iAr, iSize); cout<<"Massiv after sort"<<endl; Show(iAr, iSize); return 0; } void Init(int * iAr, int Size) { for (int i = 0; i < Size; ++i) iAr[i] = rand() % 21; } void Show(int * iAr, int Size) { for (int i = 0; i < Size; ++i) { cout<<setw(3)<<iAr[i]; } cout<<endl; } void Sort(int *iAr, int Size) { int iTemp; //int iMax; for (int i = 1; i < Size; ++i) { //iMax = i; for (int j = i; j > 0; --j) { if(iAr[j] > iAr[j - 1]) { //iMax = j; iTemp = iAr[j]; iAr[j] = iAr[j - 1]; iAr[j - 1] = iTemp; } } } }
Отредактировано Nastya (12-04-2011 15:01:41)