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; for (int i = Size - 1; i > 0; --i) { if(iAr[i] > iAr[i - 1]) { iTemp = iAr[i]; iAr[i] = iAr[i - 1]; iAr[i - 1] = iTemp; } for (int j = 1; j < Size; ++j) { int k = j; iTemp = iAr[j]; while (iTemp < iAr[k - 1]) { iAr[k] = iAr[k - 1]; --k; } iAr[k] = iTemp; } } }
Отредактировано Nastya (12-04-2011 15:54:32)