using namespace std;
void (int *sortList, int number)
{
int i = 0;
for (; i <= number; i++)
{
cout<<sortList[i]<<" ";
}
cout<<endl;
}
void insertSort( int *sortList, int number)
{
int j = 1;
for (; j <= number; j++)
{
int current = j-1;
int pre = j;
while (current >= 0 && sortList[current] > sortList[pre] )
{
int tmp = sortList[current];
sortList[current] = sortList[pre];
sortList[pre] = tmp;
current--;
pre--;
}
cout<<"the "<<j<<" time: ";
showResult(sortList,number-1);
}
}
int main (int argc, char *argv[])
{
int sortList[10] = {5, 3, 7, 4, 1, 9, 8, 6, 2, 3};
int number = 10;
insertSort(sortList,number-1);
showResult(sortList,number-1);
return 0;
}
近期评论