一、作者思路: 二、我的理解: 三、程序流程图: 四、c++代码: #include<iostream> //Sort is a class which includes a simple algorithm:InsertSort() class Sort { private: int *list; int length; public: //Initialize the list and the length of the list Sort() { std::cout<<"Please enter the number of the digits:"; std::cin>>length; list=new int[length]; std::cout<<"Please enter "<<length<<" digits:"<<std::endl; for(int i=0;i<length;i++) std::cin>>list[i]; } ~Sort() { delete [] list; } //use the direct InsertSort bool InsertSort() { int i,j,temp; for(i=1;i<length;i++) { if(list[i]<list[i-1]) { temp=list[i]; for(j=i-1;j>=0&&list[j]>temp;j--) list[j+1]=list[j]; list[j+1]=temp; } } return true; } bool ShowResult() { const char space=' '; for(int i=0;i<length;i++) std::cout<<list[i]<<space; std::cout<<std::endl; return true; } }; int main() { Sort s; s.InsertSort(); s.ShowResult(); return 0; } 五、心得体会: