Реферат: Сортировка массивов методом вставок
cout<<" 2. Sort list by decrease."<<endl<<endl;
int i;
cout<<"Your choice: ";
do {
cin>>i;
if (i<1 || i>2) cout<<endl<<"Error! Try again : "<<endl;
}while (i<1 || i>2);
switch (i)
{case 1 : SortByIncrease(); break; //Increase
case 2 : SortByDecrease(); break; //Decrease
}
}
}
/////////////////SortByIncrease//////////////////
void SortByIncrease(){
int buf;
for (int i=0; i<(n-1); i++){
if (*MasP[i]>*MasP[i+1]){
SaveList();
buf=*MasP[i+1];
for (int j=0; j<(i+1); j++){
if (buf<*MasP[j]){
for (int q=i+1; q>j; q--)
*MasP[q]=*MasP[q-1];
*MasP[j]=buf;
break;
}//Incert place
}//for Incert place
}//Find unsorted element